Is this a bug or expected behaviour in C99? - VMS

This is a discussion on Is this a bug or expected behaviour in C99? - VMS ; $ cc/version HP C V7.1-015 on OpenVMS Alpha V8.2 $ create test.c $ deck #include #include #define TEST(a, b, ...) test (a, b, ##__VA_ARGS__) static void test (int a, int b, ...) { return; } int main (void) { TEST ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: Is this a bug or expected behaviour in C99?

  1. Is this a bug or expected behaviour in C99?

    $ cc/version
    HP C V7.1-015 on OpenVMS Alpha V8.2
    $ create test.c
    $ deck
    #include
    #include

    #define TEST(a, b, ...) test (a, b, ##__VA_ARGS__)

    static void test (int a, int b, ...) {

    return;
    }

    int main (void) {

    TEST (1,2,3);
    TEST (1,2);
    }
    $ eod
    $ cc test.c

    TEST (1,2);
    ..............^
    %CC-W-TOOFEWACTUALS, Too few actual parameters in the invocation of the
    macro "T
    EST".
    at line number 14 in file MY_DISK:[000000]TEST.C;1

    TEST (1,2);
    .....^
    %CC-E-BADEXPR, Invalid expression.
    at line number 14 in file MY_DISK:[000000]TEST.C;1
    $

    I understand the TOOFEWACTUALS warning. The documentation says that the
    arguments not supplied will be given a null value. However, it appears
    that we are being literal here ;-) and the argument not supplied is
    really null, not NULL, and we end up with code after the expansion that is

    test (1, 2, );

    which produces the BADEXPR error.

    Questions: Is my code legal C99? If so, is this expected compiler
    behaviour, or is it a bug? I can't find anything in the 7.3/7.2 release
    notes (yes, I'm aware I'm on an old compiler) that seems to address this.

    Any help appreciated.

    Jim.
    --
    www.eight-cubed.com

  2. Re: Is this a bug or expected behaviour in C99?

    Jim Duff wrote:
    > $ cc/version
    > HP C V7.1-015 on OpenVMS Alpha V8.2
    > $ create test.c
    > $ deck
    > #include
    > #include
    >
    > #define TEST(a, b, ...) test (a, b, ##__VA_ARGS__)
    >
    > static void test (int a, int b, ...) {
    >
    > return;
    > }
    >
    > int main (void) {
    >
    > TEST (1,2,3);
    > TEST (1,2);
    > }
    > $ eod
    > $ cc test.c
    >
    > TEST (1,2);
    > .............^
    > %CC-W-TOOFEWACTUALS, Too few actual parameters in the invocation of the
    > macro "T
    > EST".
    > at line number 14 in file MY_DISK:[000000]TEST.C;1
    >
    > TEST (1,2);
    > ....^
    > %CC-E-BADEXPR, Invalid expression.
    > at line number 14 in file MY_DISK:[000000]TEST.C;1
    > $
    >
    > I understand the TOOFEWACTUALS warning. The documentation says that the
    > arguments not supplied will be given a null value. However, it appears
    > that we are being literal here ;-) and the argument not supplied is
    > really null, not NULL, and we end up with code after the expansion that is
    >
    > test (1, 2, );
    >
    > which produces the BADEXPR error.
    >
    > Questions: Is my code legal C99? If so, is this expected compiler
    > behaviour, or is it a bug? I can't find anything in the 7.3/7.2 release
    > notes (yes, I'm aware I'm on an old compiler) that seems to address this.
    >
    > Any help appreciated.
    >
    > Jim.
    > --
    > www.eight-cubed.com


    I tried compiling your code on a UNIX system with gcc version 2.95.2
    (which is also old). It worked, and the preprocessor output was as
    expected:

    test ( 1 , 2 ,3 ) ;
    test ( 1 , 2 ) ;

    Louis

  3. Re: Is this a bug or expected behaviour in C99?

    On 12 Sep, 11:49, Louis Krupp wrote:
    > Jim Duff wrote:
    > > $ cc/version
    > > HP C V7.1-015 on OpenVMS Alpha V8.2
    > > $ create test.c
    > > $ deck
    > > #include
    > > #include

    >
    > > #define TEST(a, b, ...) test (a, b, ##__VA_ARGS__)

    >
    > > static void test (int a, int b, ...) {

    >
    > > return;
    > > }

    >
    > > int main (void) {

    >
    > > TEST (1,2,3);
    > > TEST (1,2);
    > > }
    > > $ eod
    > > $ cc test.c

    >
    > > TEST (1,2);
    > > .............^
    > > %CC-W-TOOFEWACTUALS, Too few actual parameters in the invocation of the
    > > macro "T
    > > EST".
    > > at line number 14 in file MY_DISK:[000000]TEST.C;1

    >
    > > TEST (1,2);
    > > ....^
    > > %CC-E-BADEXPR, Invalid expression.
    > > at line number 14 in file MY_DISK:[000000]TEST.C;1
    > > $

    >
    > > I understand the TOOFEWACTUALS warning. The documentation says that the
    > > arguments not supplied will be given a null value. However, it appears
    > > that we are being literal here ;-) and the argument not supplied is
    > > really null, not NULL, and we end up with code after the expansion that is

    >
    > > test (1, 2, );

    >
    > > which produces the BADEXPR error.

    >
    > > Questions: Is my code legal C99? If so, is this expected compiler
    > > behaviour, or is it a bug? I can't find anything in the 7.3/7.2 release
    > > notes (yes, I'm aware I'm on an old compiler) that seems to address this.

    >
    > > Any help appreciated.

    >
    > > Jim.
    > > --
    > >www.eight-cubed.com

    >
    > I tried compiling your code on a UNIX system with gcc version 2.95.2
    > (which is also old). It worked, and the preprocessor output was as
    > expected:
    >
    > test ( 1 , 2 ,3 ) ;
    > test ( 1 , 2 ) ;
    >
    > Louis


    Dare I say it, it also works on M$ C/C++ Version 14.00.50727.762 (but
    not Version 12).

    But thanks for telling us that how to have macros with variable number
    of args -- I've often wondered, but never come across how to do it.

    Chris


  4. Re: Is this a bug or expected behaviour in C99?


    "Louis Krupp" wrote in message
    news:13efdi5ku0g9o14@corp.supernews.com...
    > Jim Duff wrote:


    >> Questions: Is my code legal C99?

    No.

    > I tried compiling your code on a UNIX system with gcc version 2.95.2 (which is also
    > old). It worked


    # gcc -std=c99 --pedantic test.c
    # test.c:14:14: warning: ISO C99 requires rest arguments to be used




  5. Re: Is this a bug or expected behaviour in C99?


    "Jim Duff" wrote in message
    news:46e71344@dnews.tpgi.com.au...
    > Questions: Is my code legal C99? If so, is this expected compiler
    > behaviour, or is it a bug? I can't find anything in the 7.3/7.2 release
    > notes (yes, I'm aware I'm on an old compiler) that seems to address this.


    I asked our expert (and C standard rep) about this. He confirms what
    others
    have said. This is not valid C99. There is no compiler bug here.

    Ed Vogel

    HP/Compaq/DEC C/C++ Engineering.



  6. Re: Is this a bug or expected behaviour in C99?

    On 12 Sep, 21:58, "Ed Vogel" wrote:
    > "Jim Duff" wrote in message
    >
    > news:46e71344@dnews.tpgi.com.au...
    >
    > > Questions: Is my code legal C99? If so, is this expected compiler
    > > behaviour, or is it a bug? I can't find anything in the 7.3/7.2 release
    > > notes (yes, I'm aware I'm on an old compiler) that seems to address this.

    >
    > I asked our expert (and C standard rep) about this. He confirms what
    > others
    > have said. This is not valid C99. There is no compiler bug here.
    >
    > Ed Vogel
    >
    > HP/Compaq/DEC C/C++ Engineering.


    Further investigation finds this article on exactly what is and is not
    valid C99 or an extension to it: http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html

    Chris


  7. Re: Is this a bug or expected behaviour in C99?

    Richard Brodie wrote:
    > "Louis Krupp" wrote in message
    > news:13efdi5ku0g9o14@corp.supernews.com...
    >> Jim Duff wrote:

    >
    >>> Questions: Is my code legal C99?

    > No.
    >
    >> I tried compiling your code on a UNIX system with gcc version 2.95.2 (which is also
    >> old). It worked

    >
    > # gcc -std=c99 --pedantic test.c
    > # test.c:14:14: warning: ISO C99 requires rest arguments to be used
    >
    >
    >


    Ah thanks Richard. This clearly shows it's a GCC extension. Looks like
    I'll have to dig further into the called routines to see how they deal
    with additional, unexpected NULLs (or some other VMS-specific code I
    choose for the port) passed to them.

    Jim.
    --
    www.eight-cubed.com

  8. Re: Is this a bug or expected behaviour in C99?

    Ed Vogel wrote:
    > "Jim Duff" wrote in message
    > news:46e71344@dnews.tpgi.com.au...
    >> Questions: Is my code legal C99? If so, is this expected compiler
    >> behaviour, or is it a bug? I can't find anything in the 7.3/7.2
    >> release notes (yes, I'm aware I'm on an old compiler) that seems to
    >> address this.

    >
    > I asked our expert (and C standard rep) about this. He confirms what
    > others have said. This is not valid C99. There is no compiler bug
    > here.
    >
    > Ed Vogel
    >
    > HP/Compaq/DEC C/C++ Engineering.
    >
    >


    Ed,

    Thanks for the definitive reply.

    Jim.
    --
    www.eight-cubed.com

  9. Re: Is this a bug or expected behaviour in C99?

    chrisj.doran@proemail.co.uk wrote:
    > On 12 Sep, 21:58, "Ed Vogel" wrote:
    >> "Jim Duff" wrote in message
    >>
    >> news:46e71344@dnews.tpgi.com.au...
    >>
    >>> Questions: Is my code legal C99? If so, is this expected compiler
    >>> behaviour, or is it a bug? I can't find anything in the 7.3/7.2 release
    >>> notes (yes, I'm aware I'm on an old compiler) that seems to address this.

    >> I asked our expert (and C standard rep) about this. He confirms what
    >> others
    >> have said. This is not valid C99. There is no compiler bug here.
    >>
    >> Ed Vogel
    >>
    >> HP/Compaq/DEC C/C++ Engineering.

    >
    > Further investigation finds this article on exactly what is and is not
    > valid C99 or an extension to it: http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
    >
    > Chris
    >


    I read that article. And I totally missed the bit about ##__VA_ARGS__
    being a gcc extension.

    Louis

  10. Re: Is this a bug or expected behaviour in C99?

    Jim Duff wrote:
    > Richard Brodie wrote:
    >> "Louis Krupp" wrote in message
    >> news:13efdi5ku0g9o14@corp.supernews.com...
    >>> Jim Duff wrote:
    >>>> Questions: Is my code legal C99?

    >> No.
    >>
    >>> I tried compiling your code on a UNIX system with gcc version 2.95.2 (which is also
    >>> old). It worked

    >> # gcc -std=c99 --pedantic test.c
    >> # test.c:14:14: warning: ISO C99 requires rest arguments to be used
    >>
    >>
    >>

    >
    > Ah thanks Richard. This clearly shows it's a GCC extension. Looks like
    > I'll have to dig further into the called routines to see how they deal
    > with additional, unexpected NULLs (or some other VMS-specific code I
    > choose for the port) passed to them.


    If you're desperate (and if you don't have too many calls to TEST), you
    could do something like this:

    #define COMMA ,
    #define TEST(x) test("hello", 7, x)

    static void test (int a, int b, ...) {
    return;
    }

    int main (void) {
    TEST (1 COMMA 2 COMMA 3);
    TEST (1 COMMA 2);
    }

    gcc -E produces:

    int main (void) {
    test("hello", 7, 1 , 2 , 3 ) ;
    test("hello", 7, 1 , 2 ) ;
    }

+ Reply to Thread