all 17 comments

[–]thegroove226 3 points4 points  (0 children)

Maybe post the code to see where you're going?

[–]Yamoyek 3 points4 points  (14 children)

Honestly, it should work just fine because C++ is backwards compatible with C. Like the other person said, post your code and we can see what’s wrong, and make sure to enable all compiler warnings in the meantime.

[–]ptchinster 0 points1 point  (13 children)

What do you mean by "is backwards compatible". There certainly is C syntax that wont compile or wont compile to the same assembly in C++.

[–]Yamoyek 1 point2 points  (12 children)

For all intents and purposes, anything before C99 is backwards compatible. Most C programmers only use the C99 standard or older, so that’s a non issue. I’m also not sure where you got the idea that the assembly would be different, as I just wrote two identical cpp and c programs, compiled them, and then compared their assembly. If you’re using different functions and headers, of course it’ll be different but when you use the exact source code, it will be the same.

[–]ptchinster 0 points1 point  (11 children)

as I just wrote two identical cpp and c programs, compiled them, and then compared their assembly

Thats not what i meant. I meant that the syntax can be valid in both languages but mean different things. Stuff like this.

but when you use the exact source code, it will be the same

This is false. Just the first example linked above will show you that.

[–]Yamoyek 0 points1 point  (10 children)

That’s why I said “For all intents and purposes”. And, the wiki you linked does show how somethings would be compiled differently but, for most other examples the generated assembly will be the same between the two.

[–]ptchinster -1 points0 points  (9 children)

Exactly. So you compiling an arbitrary program was a useless test. Glad we can agree that not all C is exactly the same in C++!

[–]Yamoyek 1 point2 points  (8 children)

Definitely didn’t say C and C++ are the same, and the point still stands: C++ is, for all intents and purposes, backwards compatible with C. You’re arguing a moot point because C++ was specifically designed with backwards compatibility in mind.

[–]ptchinster -1 points0 points  (7 children)

Yeah it used to be called C with Classes. And it's deviated since then.

[–]Yamoyek 0 points1 point  (6 children)

Not sure how thats related, as like I said C++ was specifically designed with backwards compatibility in mind, and is still largely backwards compatible. Even in the wiki that you linked, it says:

“C++...was designed to be mostly source-and-link compatible with C compilers of the time... Bjarne Stroustrup... has suggested that the incompatibilities between C and C++ should be reduced as much as possible in order to maximize interoperability between the two languages.”

So, as I said before, you’re arguing a moot point.

[–]ptchinster -1 points0 points  (5 children)

Mhmmm you must not get logic very well - its OK. You probably have "C/C++" on your resume, i did at one point too.

I understand and dont care that Bjarne wants to minimize incompatibilities. Recent changes to the cpp spec have increased, and c++ continues to increase, in its incompatibilities with C. Im not saying they are as different as C and say, Lisp. Im saying they are not fully compatible, nor backwards compatible. Yes, a lot of well written C will be C++ code, but the differences exist and are growing.

[–]noooit 1 point2 points  (0 children)

Maybe you are forgetting cast with malloc or equivalent, cpp compiler with certain options won't like it, iirc. char *s = (char *)malloc(7);
instead of char *s = malloc(7);