c++ is a subset of c, or maybe it's the otehr way round i 4got that crap, but anyhow, piont is, u can't.
infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
>How am i supposed to write a code in c which compiles in c but not in c++
#include <stdio.h>
int main(void)
{
char new[] = "Compiles in C, not in C++";
puts(new);
return 0;
}
That is, one way would be to use a C++ (and not C) keyword as a variable.
[EDIT]
Another way.
#include <stdio.h>
#ifdef __cplusplus
#error Prevented from compiling as C++
#endif
int main(void)
{
puts("Hello world");
return 0;
}
[/EDIT]
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
Hi,
C++ is a superset of C.
I can only wonder WHY you would want to try to compile something that works with C only? That doesn't make sense.
Christian
kc0arf
Posting Virtuoso
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57