c++ bullshit – Character arrays and the null terminator

The C++ standard states

There shall not be more initializers than there are array elements. [Example:
char cv[4] = "asdf"; // error
is ill-formed since there is no space for the implied trailing ’\0’. —end example ]

Well that seems kind of reasonable at first glance, however on closer inspection this rule makes it impossible to define a non null terminated character array using a string literal as the initializer. The only “legal” way to accomplish this would be to use array syntax and specify each character individually.

char cv[4] = {'a','s','d','f'};

This is BULLSHIT, it makes the code ugly, harder to write, harder to read, and more difficult to maintain. This rule imposes unreasonable constraints on the programmer, he should not be forced to define a character array this way. The rule itself however is not in error, it is the fact that there is no way to define a non null-terminated string literal that is the problem.

Now most programmers would just submit to this tyranny, but I shall not yield. I shall hack the compiler to disable this rule until such time (probably never) that those retards who maintain the c++ standard correct this grievous mistake.

GCC compiler hacks

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s