Error

Now getting this error when compiling this macro:


Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#include <stdio.h>

#define swap(t,x,y) \

( t type = x; x = y; y = type; )



int main()
	
{


int x, y;
x = 2, y = 10;

swap(int, x, y);

printf("%d %d\n", x, y);

return 0;


}


Line 6 is not part of the macro, but line 5 is.

Why are you forced to use C instead of C++? std::swap is a much better alternative.
Last edited on
Change that:
( t type = x; x = y; y = type; )
to this:
{ t type = x; x = y; y = type; }
@LB C++ is a monstrously complicated language.

@skaa

Still getting the same error.

closed account (E0p9LyTq)
@pacman169

C++ is more "complicated" than C because it can do things in a line or three of code that in C either requires a large number of code lines or is impossible.
@pacman169, try this code:
1
2
3
4
5
6
7
8
9
#define swap2(t,x,y) { t type = x; x = y; y = type; }
void	main()
{
  int	x,y;

  x=2;y=10;

  swap2(int,x,y);
}

, tested in Borland C++ Builder 5.0, works fine.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream> // cout, endl
#include <algorithm> // swap

using namespace std;
int main()
{
    int x = 2;
    int y = 10;
    swap(x,y);
    cout << x << ' ' << y << endl;
}


Oh wow this is hard
pacman169 wrote:
C++ is a monstrously complicated language.
I always recommend the simplest correct solution to a problem. Don't be turned off from an entire language just because it is possible to write horrifyingly complex code with it. Personally I am fearful of having to work in the limitations of C.
Last edited on
I'm also somewhat fearful of having to work within the limitations of most anything other than C++ since that's what I've always used (FYI I mean speed limitations mainly). I also don't get why people use C when you can compile C as C++ and then when you have to additional features of C++, you'll just find so many simplification and optimisations that can be done easily.
Topic archived. No new replies allowed.