Re:Tbox: A GLib-like cross-platform C library
by waruqi on Friday April 12, 2019 @08:07AM
(#19644032)
C89 cannot mix variable declarations and code.
printf("Hello World!\n");
int x = 7;
printf("%d!\n", x);
return 0;
This is a very serious restriction for me.
Re:Tbox: A GLib-like cross-platform C library
by Crinus on Friday April 12, 2019 @10:39AM
(#19645167)
Yes, that is what i meant with "inline variables". IMO this is usually a sign of code that is too long to be readable and if you really need that you should either split the function to make it more readable or, if that cannot be done, enclose the affected code in their own brackets (with a comment that makes it easy to distinguish). Brackets also make sure that the variable wont "outlive" its context (although again that is a sign of code that is too long).
Of course that is my opinion (and i'm generalizing of course), but that comes from my experience with working with others' code.
Re:Tbox: A GLib-like cross-platform C library
by waruqi on Friday April 12, 2019 @10:53AM
(#19645271)
Even if the function code is very short, I still like to define and declare variables nearby.
Unless a function has only two lines of code.
Re:Tbox: A GLib-like cross-platform C library
by Crinus on Friday April 12, 2019 @11:20AM
(#19645562)
Right, that is your style, but i wouldn't call that "too many grammar restrictions" :-).
Re:Tbox: A GLib-like cross-platform C library
by WoodenChair on Friday April 12, 2019 @11:43AM
(#19645820)
It's too many grammar restrictions for this person. That's obviously what's implied by the person's original comment.
The versions do have other differences, of course, but they're rarely used (the next most common one is designated initializers, which for me are the most annoying to convert).
I mean, it is your code, i just found the grammar restrictions part weird since really there isn't that much of a practical difference between C99 and C89 to the point i personally never felt the need to use C99.
(note that i focus on the language bits, C99 provides some extra library functionality but even then the most useful part is stdint.h which can be implemented in almost any C89 compiler anyway)