Diagnostics (continued)

Discussion in 'C Programming' started by jacob navia, Jul 15, 2008.

  1. jacob navia

    jacob navia Guest

    Consider this nice C program:

    short long n;
    signed unsigned b;
    const long const long a;
    unsigned double w;
    signed float k;
    short double q;
    unsigned long double z;

    I was astonished that my dear lcc-win very bad diagnostic messages
    wrote for those errors.

    After correcting that, I passed this code through MSVC and it
    wrote a correct diagnostic for all of those errors... excepting
    the last.

    unsigned long double is legal?

    I have serious doubts.

    Besides, MSVC emitted just a warning for repeated qualifiers like
    "const long const long"... Isn't that an error?

    gcc wrote correct diagnostics for all of them, and all were errors,
    not warnings.

    PellesC missed "const long const long" completely, but the errors
    were as I had it: just "Invalid type specification" instead of a
    more specific error.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Jul 15, 2008
    #1
    1. Advertising

  2. jacob navia <> writes:
    > Consider this nice C program:
    >
    > short long n;
    > signed unsigned b;
    > const long const long a;
    > unsigned double w;
    > signed float k;
    > short double q;
    > unsigned long double z;
    >
    > I was astonished that my dear lcc-win very bad diagnostic messages
    > wrote for those errors.
    >
    > After correcting that, I passed this code through MSVC and it
    > wrote a correct diagnostic for all of those errors... excepting
    > the last.
    >
    > unsigned long double is legal?
    >
    > I have serious doubts.


    No, ``unsigned long double'' is a constraint violation, as you can
    verify by re-reading C99 6.7.2, Type specifiers.

    > Besides, MSVC emitted just a warning for repeated qualifiers like
    > "const long const long"... Isn't that an error?


    No, type *specifiers* may not be repeated (other than "long long" and
    variations), but type *qualifiers* such as "const" may be repeated, so
    "const long const long" is equivalent to "const long long". (It's
    ugly, though, so a warning seems appropriate, though it's not
    required.)

    C99 6.7.3p4:

    If the same qualifier appears more than once in the same
    _specifier-qualifier-list_, either directly or via one or more
    typedefs, the behavior is the same as if it appeared only once.

    The idea, I think, is that if you have a typedef for "const int", you
    can still apply "const" to the typedef:

    typedef const int c_int;
    const c_int x = 42;

    (IMHO "const" belongs on the object declaration, not buried in a
    typedef, but the language allows it.)

    In any case, as you know, the standard doesn't distinguish between
    errors and warnings. A warning that doesn't cause translation to fail
    can still be a valid "diagnostic message" as required by the standard.

    > gcc wrote correct diagnostics for all of them, and all were errors,
    > not warnings.


    Ok, but many of gcc's required diagnostic are warnings.

    > PellesC missed "const long const long" completely,


    Probably because it's valid.

    > but the errors
    > were as I had it: just "Invalid type specification" instead of a
    > more specific error.


    I don't feel strongly that a more specific error message is necessary,
    but that's up to you.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Jul 15, 2008
    #2
    1. Advertising

  3. jacob navia

    Guest

    Keith Thompson <> wrote:
    >
    > (IMHO "const" belongs on the object declaration, not buried in a
    > typedef, but the language allows it.)


    And, as I recall, one of the key arguments for allowing redundant
    qualifiers in C99 was that sig_atomic_t is allowed to be a volatile
    qualified type and without allowing redundant qualifiers there was no
    portable way to declare an object of that type that was *guaranteed* to
    be volatile.
    --
    Larry Jones

    Fortunately, that was our plan from the start. -- Calvin
    , Jul 16, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Dupont
    Replies:
    1
    Views:
    362
    Lloyd Dupont
    Sep 30, 2004
  2. Lloyd Dupont
    Replies:
    1
    Views:
    428
    Guest
    Dec 22, 2004
  3. =?Utf-8?B?S2lzaG9yZSBHb3BhbGFu?=

    (continued...System.Security.SecurityException

    =?Utf-8?B?S2lzaG9yZSBHb3BhbGFu?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    373
  4. joel s
    Replies:
    0
    Views:
    299
    joel s
    Nov 3, 2003
  5. Jeff
    Replies:
    3
    Views:
    802
    Jon A. Cruz
    Jan 17, 2004
Loading...

Share This Page