PDA

View Full Version : sprintf() and SDK 10.6




Appleness
Nov 12, 2009, 07:15 AM
I am developing command line apps in C.

Having turned off 64 bits and chosen GCC 4.0 (otherwise my programs crash), I found some strange behaviour with sprintf() function.

If I build the project with SDK 10.5 it works fine, but if I choose 10.6 it crashes. I noticed that (with 10.6) the editor shows "sprintf" in other color (different from printf statements), as if they were preprocessor statements.

What am I doing wrong?

Thanks



lee1210
Nov 12, 2009, 08:09 AM
post your code. this is pretty vague, and without more information we can't really do much for you.

-Lee

Cromulent
Nov 12, 2009, 08:55 AM
If your programs crash when you try and compile them with anything other than GCC 4 then it suggests you have some strange issues. I'm not even sure what GCC 4 specific items were removed from GCC 4.2 or even Clang for that matter (which has attempted to remain compatible with GCC extensions).

gnasher729
Nov 12, 2009, 09:24 AM
I am developing command line apps in C.

Having turned off 64 bits and chosen GCC 4.0 (otherwise my programs crash), I found some strange behaviour with sprintf() function.

If I build the project with SDK 10.5 it works fine, but if I choose 10.6 it crashes. I noticed that (with 10.6) the editor shows "sprintf" in other color (different from printf statements), as if they were preprocessor statements.

What am I doing wrong?

Thanks

I don't know what you are doing wrong, but if it runs with GCC 4.0 and not with GCC 4.2 or clang, then 99.99% it is something wrong with your code. Uninitialised variables, dependence on order of evaluation, lots of things that can go wrong with one compiler and work with an other, but all bugs in the original code.

As an example, take

char buffer [10];
long x;

sprintf (buffer, "%ld", x);


and think about why this code might crash on one compiler and not on another, and why it is more likely to crash on a 64 bit system.

Appleness
Nov 12, 2009, 10:51 AM
Thanks for your replies.

I gave it for granted that if one code worked with GCC 4.0, it would too with 4.2. Now I see that I probably have wrong code anywhere.

I will check it all (thousands of lines, God!), and I will post if I find anything interesting.

Thanks again

chown33
Nov 12, 2009, 12:13 PM
Use the debugger. If you don't know how, then now might be a good time to learn. Especially compared to the time it will take you to manually inspect all your code.

If it's C or Obj-C code, you might also run it through the static analyzer in Xcode 3.2. Google keywords: xcode static analyzer.

Catfish_Man
Nov 12, 2009, 12:30 PM
Yeah, manual code inspection is rarely an efficient way to work. Use the debugger, GuardMalloc, etc... there are *tons* of tools for dealing with this stuff.