C++ compilation fails without -fpermissive #262

Closed
opened 2026-01-29 20:41:02 +00:00 by claunia · 3 comments
Owner

Originally created by @very-cool-name on GitHub (Nov 23, 2018).

Hello! Is there a specific reason why this character array implemented with explicit '\0' in the end?

5805f99a53/c/common/transform.c (L14)

It fails to compile on C++ compiler with error:
error: initializer-string for array of chars is too long [-fpermissive]

Is it possible to write it without specifying size? I.e. :
static const char kPrefixSuffix[] = "...."

I've looked at disassembled code https://godbolt.org/z/cwc5Xi and don't see much difference, except copying from register.

Originally created by @very-cool-name on GitHub (Nov 23, 2018). Hello! Is there a specific reason why this character array implemented with explicit '\0' in the end? https://github.com/google/brotli/blob/5805f99a533a8f8118699c0100d8c102f3605f65/c/common/transform.c#L14 It fails to compile on C++ compiler with error: `error: initializer-string for array of chars is too long [-fpermissive]` Is it possible to write it without specifying size? I.e. : `static const char kPrefixSuffix[] = "...."` I've looked at disassembled code https://godbolt.org/z/cwc5Xi and don't see much difference, except copying from register.
Author
Owner

@very-cool-name commented on GitHub (Nov 26, 2018):

Or if for some reason number 217 is necessary, you can use array initialization:
static const char kPrefixSuffix[217] = {'\1', ' ', '\2', ',', ' ', ...}
tedious, but you have to write it only once.

@very-cool-name commented on GitHub (Nov 26, 2018): Or if for some reason number 217 is necessary, you can use array initialization: `static const char kPrefixSuffix[217] = {'\1', ' ', '\2', ',', ' ', ...}` tedious, but you have to write it only once.
Author
Owner

@eustas commented on GitHub (Feb 18, 2019):

Luckily, the last character is \0. We can just remove it... Will fix very soon.

@eustas commented on GitHub (Feb 18, 2019): Luckily, the last character is `\0`. We can just remove it... Will fix very soon.
Author
Owner

@eustas commented on GitHub (Apr 12, 2019):

Will be fixed with #749

@eustas commented on GitHub (Apr 12, 2019): Will be fixed with #749
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#262