This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: fix handling of '#pragma pack(pop [, id])'
- To: Mike Coleman <mcoleman2 at kc dot rr dot com>
- Subject: Re: fix handling of '#pragma pack(pop [, id])'
- From: "Zack Weinberg" <zackw at stanford dot edu>
- Date: Fri, 29 Sep 2000 21:55:17 -0700
- Cc: gcc-patches at gcc dot gnu dot org
- References: <m13fDpG-001qXNC@microdog>
On Fri, Sep 29, 2000 at 11:00:38PM -0500, Mike Coleman wrote:
> This patch fixes a problem with '#pragma pack(pop [, id])', which is a MSVC
> compatibility feature AFAIK. The current parser insists on the same form for
> 'push' and 'pop' both
>
> #pragma pack(push [, id], <n>)
> #pragma pack(pop [, id], <n>)
>
> but the 'pop' form shouldn't require (or allow, I think) the numeric
> parameter. It should parse this
>
> #pragma pack(pop [, id])
>
> instead. This patch fixes the problem, and gives slightly clearer error
> messages.
...
> + const char *badmsg;
> if (!strcmp (op, "push"))
> ! {
> ! action = push;
> ! badmsg = "malformed '#pragma pack(push[, id], <n>)' - ignored";
> ! }
> else if (!strcmp (op, "pop"))
> ! {
> ! action = pop;
> ! badmsg = "malformed '#pragma pack(pop[, id])' - ignored";
> ! }
> else
> BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op);
>
> if (c_lex (&x) != CPP_COMMA)
> ! BAD (badmsg);
You must not use a variable to hold an error message, or message
translation will break. You have to do it like this:
if (c_lex (&x) != CPP_COMMA)
{
if (action == push)
BAD ("malformed '#pragma pack(push[, id], <n>)' - ignored");
else
BAD ("malformed '#pragma pack(pop[, id])' - ignored");
}
> ! if (action != pop)
> ! switch (align)
> ! {
> ! case 0:
> ! case 1:
> ! case 2:
> ! case 4:
> ! case 8:
> ! case 16:
> ! align *= BITS_PER_UNIT;
> ! break;
> ! default:
> ! BAD2 ("alignment must be a small power of two, not %d", align);
> ! }
Better you should set align to zero at the beginning of the function
and leave the switch alone.
zw