5 ms·
C isn't C++. Most of what you know today applies to older compilers as well, with only a handful of features added over the years. You aren't going all the wa
by jandrese 3y ago
C isn't C++. Most of what you know today applies to older compilers as well, with only a handful of features added over the years. You aren't going all the way back to K&R calling syntax here, I'm assuming you will target C89. You will just have to remember to declare all of your variables at the top of each function and the stdint types won't be available. There are a few other things added over the years, but its going to be pretty much the C you know and love.
- lockhouse 3y agoPedantically you are correct, but it is and was common to use C++ compilers as a slightly more convenient dialect of C. This gives you the performance and simplicity of the C language with some very nice quality of life improvements. With few exceptions, C++ can mostly be treated as a superset of C.
- jandrese 3y agoWhat I was trying to say is that if you're comfortable using modern C++ and try to switch back to a C++ compiler from the early 90s you are going to find a lot of the features you regularly use suddenly being absent. With C this is much less of an issue.
- lockhouse 3y agoSorry, I misread your comment, that makes a lot more sense now!
- duskwuff 3y agoThe newer C features that you're most likely to feel the lack of in an older compiler are: 1) Mixed declarations and code. All variables must be declared at the top of a basic block. 2) Along similar lines, declaring variables in control statements like for(). 3) // comments. (Hardly a critical feature, but you're probably used to having them.) Perhaps not coincidentally, I think these were all features which began their life in C++, and were backported to C in C99.
- ido 3y agoIIRC they were also available as “non-standard” feature in compilers at the time before being added to c99 (e.g. I’m pretty sure gcc in the late 90s supported all of these if you didn’t force c89 compatibility).
- badsectoracula 3y ago> I'm assuming you will target C89 OpenWatcom (the compiler the parent post mentioned) supports C99.
- aninteger 3y agoNot by default, it does require a flag (-za99).
- badsectoracula 3y agoYeah but that doesn't really mean anything, the compiler still supports C99 if one wants to write in it.
- deaddodo 3y ago> You will just have to remember to declare all of your variables at the top of each function This is still idiomatic to the C community, even if it isn't strictly required any longer. About the only place it's ignored is inline variables for loops.
- vkoskiv 3y agoI write C primarily for hobby projects, and I only started with C ~10 years ago, so I'm likely in the minority that considers this a code smell for new C code. I don't want to needlessly extend the scope of my local variables! Different story of course if you're targeting C89 or older, which I'm actually doing in my current project. I'm writing software on and for my old 68k Macintosh.
- deaddodo 3y ago<< Edited out for being unnecessarily combative >>
- jandrese 3y agoWe might be saying the same thing here, but modern C scopes variables down to the block. So if you have a variable declared for instance inside of a for loop or if statement, that variable is out of scope once you exit the block. This will fail to compile with an "undeclared identifier" error: if ( x > 0 ) { int y = 1; } printf("%d", y); It is a feature that was long overdue in C IMHO.