Spot the bug: wchar_t buf[123]; swprintf(buf, sizeof buf, "%s/%d", str, num);
That's much worse. It creates an obligation to keep multiple things consistent, and it's not genericizable.
-
-
what do you mean? enum { length = 123 }; …
-
Now you need a convention for naming the length of each buffer object/struct-field, a way to namespace them, ...
-
...and if you accidentally mix up which goes with which, you have buffer overflows. snprintf(buf, sizeof buf, ...) is always ok.
-
ok, the constant works only for local arrays. The other obvious improvement over sizeof is an ARRAY_LENGTH macro.
-
Yes,
#define countof(arr) (sizeof(arr)/sizeof(*arr)) -
But when ppl have to remember to use a countof rather than a sizeof, you have a security UX problem for programmers.
-
is there anything in C that is not a security UX problem?
-
Every interface not involving any pointers.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.