“Quirks and features”
Lesser known tricks, quirks and features of C
11–20 of 189 posts
Re: Lesser known tricks, quirks and features of C
#12Nice article. Saw a few things I wish I'd known about. 1. %n in printf would be handy when writing CLIs dealing w/ multiple lines or precise counts of backspaces. 2. Using enums as a form of static_assert() is a great idea (triggering a div by zero compiler error).
%n is for bytes, not user-perceived characters.
Re: Lesser known tricks, quirks and features of C
#13Here's another one. Handy "syntax" that makes it possible to iterate an unsigned type from N-1 to 0. (Normally this is tricky.) for (unsigned int i = N; i --> 0;) printf("%d\n", i); This --> construction also works in JavaScript and so on.
Re: Lesser known tricks, quirks and features of C
#14Re: Lesser known tricks, quirks and features of C
#15Re: Lesser known tricks, quirks and features of C
#16Re: Lesser known tricks, quirks and features of C
#17Re: Lesser known tricks, quirks and features of C
#18> The 0 width field tells that the following bit fields should be set on the next atomic entity (char). This isn't correct since int can't be less than 16-bits. Fields are placed on the nearest natural alignment for the target platform, which might not support unaligned access.
The bitfield stuff in C would be fantastic if it weren't fundamentally broken. E.g. some Microsoft compilers in the past interpreted bit fields as signed...always. In V8 we had a work around with templates to avoid bitfields altogether. Fail.
Re: Lesser known tricks, quirks and features of C
#19Yet another proof that C is simple but not easy.
Re: Lesser known tricks, quirks and features of C
#20> The 0 width field tells that the following bit fields should be set on the next atomic entity (char). This isn't correct since int can't be less than 16-bits. Fields are placed on the nearest natural alignment for the target platform, which might not support unaligned access.