Is it just me or just Microsoft?

Discussion in 'C Programming' started by Ark Khasin, Jul 15, 2007.

  1. Ark Khasin

    Ark Khasin Guest

    Due to a peculiar need (code instrumentation) I came across unexpected
    behavior of Visual Studio 6.0 and 2005 (doing the same thing):

    #include <stdio.h>
    #define CAT1(a,b) a ## b
    #define CAT(a,b) CAT1(a,b)
    #define MYNUM(n) CAT(n,__LINE__)
    const int x = MYNUM(35); //OK
    int z=MYNUM(78); //OK
    int main(int argc)
    {
    static int y=MYNUM(21); //error!
    //6.0: error C2064: term doesn't evaluate to a function
    //2005 adds: taking 26451848 arguments.

    printf("%d %d\n", x, y );
    return 0;
    }

    Doesn't matter if I compile as C or as C++ (if I am not mistaken, the
    preprocessor is the same).
    No problem with another compiler (IAR for ARM)...
    [Microsoft claims strict standard compliance in the C++ department]

    Any suggestions?

    Thank you,
    Ark
    Ark Khasin, Jul 15, 2007
    #1
    1. Advertising

  2. Ark Khasin

    GeekBoy Guest

    "Ark Khasin" <> wrote in message
    news:pbfmi.4059$7R4.1870@trndny09...
    > Due to a peculiar need (code instrumentation) I came across unexpected
    > behavior of Visual Studio 6.0 and 2005 (doing the same thing):
    >
    > #include <stdio.h>
    > #define CAT1(a,b) a ## b
    > #define CAT(a,b) CAT1(a,b)
    > #define MYNUM(n) CAT(n,__LINE__)
    > const int x = MYNUM(35); //OK
    > int z=MYNUM(78); //OK
    > int main(int argc)
    > {
    > static int y=MYNUM(21); //error!
    > //6.0: error C2064: term doesn't evaluate to a function
    > //2005 adds: taking 26451848 arguments.
    >
    > printf("%d %d\n", x, y );
    > return 0;
    > }
    >
    > Doesn't matter if I compile as C or as C++ (if I am not mistaken, the
    > preprocessor is the same).
    > No problem with another compiler (IAR for ARM)...
    > [Microsoft claims strict standard compliance in the C++ department]
    >
    > Any suggestions?



    Yeah, buy a compiler that is ANSI/ISO compliant


    >
    > Thank you,
    > Ark
    GeekBoy, Jul 15, 2007
    #2
    1. Advertising

  3. Ark Khasin

    Ark Khasin Guest

    GeekBoy wrote:
    > "Ark Khasin" <> wrote in message
    > news:pbfmi.4059$7R4.1870@trndny09...
    >> Due to a peculiar need (code instrumentation) I came across unexpected
    >> behavior of Visual Studio 6.0 and 2005 (doing the same thing):
    >>
    >> #include <stdio.h>
    >> #define CAT1(a,b) a ## b
    >> #define CAT(a,b) CAT1(a,b)
    >> #define MYNUM(n) CAT(n,__LINE__)
    >> const int x = MYNUM(35); //OK
    >> int z=MYNUM(78); //OK
    >> int main(int argc)
    >> {
    >> static int y=MYNUM(21); //error!
    >> //6.0: error C2064: term doesn't evaluate to a function
    >> //2005 adds: taking 26451848 arguments.
    >>
    >> printf("%d %d\n", x, y );
    >> return 0;
    >> }
    >>
    >> Doesn't matter if I compile as C or as C++ (if I am not mistaken, the
    >> preprocessor is the same).
    >> No problem with another compiler (IAR for ARM)...
    >> [Microsoft claims strict standard compliance in the C++ department]
    >>
    >> Any suggestions?

    >
    >
    > Yeah, buy a compiler that is ANSI/ISO compliant
    >
    >
    >> Thank you,
    >> Ark

    >

    Easier said than done. Many people are bound to MS tools. I guess I
    was asking for help with a workaround within MS if known.
    - Ark
    Ark Khasin, Jul 15, 2007
    #3
  4. * Ark Khasin:
    > Due to a peculiar need (code instrumentation) I came across unexpected
    > behavior of Visual Studio 6.0 and 2005 (doing the same thing):
    >
    > #include <stdio.h>
    > #define CAT1(a,b) a ## b
    > #define CAT(a,b) CAT1(a,b)
    > #define MYNUM(n) CAT(n,__LINE__)
    > const int x = MYNUM(35); //OK
    > int z=MYNUM(78); //OK
    > int main(int argc)
    > {
    > static int y=MYNUM(21); //error!
    > //6.0: error C2064: term doesn't evaluate to a function
    > //2005 adds: taking 26451848 arguments.
    >
    > printf("%d %d\n", x, y );
    > return 0;
    > }
    >
    > Doesn't matter if I compile as C or as C++ (if I am not mistaken, the
    > preprocessor is the same).
    > No problem with another compiler (IAR for ARM)...
    > [Microsoft claims strict standard compliance in the C++ department]
    >
    > Any suggestions?


    Visual C++ __LINE__ is broken in many versions of that compiler, when
    you compile with support for "Edit and Continue" (option /ZI), and that
    may be what you're up against. As an alternative you can use
    non-standard __COUNTER__. And the only thing that makes that compiler
    specific information slightly on-topic here is that it's an issue with
    Marginean's original scope guard (which is of general interest to the
    C++ community), which needs to be modified for use with Visual C++.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jul 15, 2007
    #4
  5. In article <469981e9$0$30620$>,
    GeekBoy <> wrote:
    >
    >"Ark Khasin" <> wrote in message
    >news:pbfmi.4059$7R4.1870@trndny09...
    >> Due to a peculiar need (code instrumentation) I came across unexpected
    >> behavior of Visual Studio 6.0 and 2005 (doing the same thing):


    [...]

    >> Any suggestions?

    >
    >Yeah, buy a compiler that is ANSI/ISO compliant


    MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    it's invoked properly. Its C++ compiler pre-dates the last two versions
    of the C++ standard and I don't have any experience with newer versions,
    but I would be surprised if they don't at least closely approximate
    compliance.

    I'm unable to duplicate it with MSVC6, so it looks to me like it's
    probably something specific to the OP's installation; but in any case
    it's highly unlikely to be a deliberate non-compliance with the standard.


    dave

    --
    Dave Vandervies
    There are some rather entertaining LARTs that can be applied if you have the
    will and moderately deep pockets to play with lawyers.
    --Peter Corlett in the scary devil monastery
    Dave Vandervies, Jul 15, 2007
    #5
  6. Ark Khasin

    Ark Khasin Guest

    Dave Vandervies wrote:
    <snip>
    > MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    > it's invoked properly.

    <snip>

    You must be kidding.
    - Ark
    Ark Khasin, Jul 15, 2007
    #6
  7. In article <i1gmi.4064$7R4.1703@trndny09>,
    Ark Khasin <> wrote:
    >Dave Vandervies wrote:
    ><snip>
    >> MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    >> it's invoked properly.

    ><snip>
    >
    >You must be kidding.
    >- Ark


    No, I'm not. I have a lot of reasons to hate Microsoft, but their C
    compiler isn't one of them.


    dave

    --
    Dave Vandervies
    There are some rather entertaining LARTs that can be applied if you have the
    will and moderately deep pockets to play with lawyers.
    --Peter Corlett in the scary devil monastery
    Dave Vandervies, Jul 15, 2007
    #7
  8. * Alf P. Steinbach:
    > * Ark Khasin:
    >> Due to a peculiar need (code instrumentation) I came across unexpected
    >> behavior of Visual Studio 6.0 and 2005 (doing the same thing):
    >>
    >> #include <stdio.h>
    >> #define CAT1(a,b) a ## b
    >> #define CAT(a,b) CAT1(a,b)
    >> #define MYNUM(n) CAT(n,__LINE__)
    >> const int x = MYNUM(35); //OK
    >> int z=MYNUM(78); //OK
    >> int main(int argc)
    >> {
    >> static int y=MYNUM(21); //error!
    >> //6.0: error C2064: term doesn't evaluate to a function
    >> //2005 adds: taking 26451848 arguments.
    >>
    >> printf("%d %d\n", x, y );
    >> return 0;
    >> }
    >>
    >> Doesn't matter if I compile as C or as C++ (if I am not mistaken, the
    >> preprocessor is the same).
    >> No problem with another compiler (IAR for ARM)...
    >> [Microsoft claims strict standard compliance in the C++ department]
    >>
    >> Any suggestions?

    >
    > Visual C++ __LINE__ is broken in many versions of that compiler, when
    > you compile with support for "Edit and Continue" (option /ZI), and that
    > may be what you're up against. As an alternative you can use
    > non-standard __COUNTER__. And the only thing that makes that compiler
    > specific information slightly on-topic here is that it's an issue with
    > Marginean's original scope guard (which is of general interest to the
    > C++ community), which needs to be modified for use with Visual C++.


    Just another suggestion: your "main" signature is incorrect.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jul 15, 2007
    #8
  9. Ark Khasin

    Ark Khasin Guest

    Alf P. Steinbach wrote:
    > * Ark Khasin:
    >> Due to a peculiar need (code instrumentation) I came across unexpected
    >> behavior of Visual Studio 6.0 and 2005 (doing the same thing):
    >>
    >> #include <stdio.h>
    >> #define CAT1(a,b) a ## b
    >> #define CAT(a,b) CAT1(a,b)
    >> #define MYNUM(n) CAT(n,__LINE__)
    >> const int x = MYNUM(35); //OK
    >> int z=MYNUM(78); //OK
    >> int main(int argc)
    >> {
    >> static int y=MYNUM(21); //error!
    >> //6.0: error C2064: term doesn't evaluate to a function
    >> //2005 adds: taking 26451848 arguments.
    >>
    >> printf("%d %d\n", x, y );
    >> return 0;
    >> }
    >>
    >> Doesn't matter if I compile as C or as C++ (if I am not mistaken, the
    >> preprocessor is the same).
    >> No problem with another compiler (IAR for ARM)...
    >> [Microsoft claims strict standard compliance in the C++ department]
    >>
    >> Any suggestions?

    >
    > Visual C++ __LINE__ is broken in many versions of that compiler, when
    > you compile with support for "Edit and Continue" (option /ZI), and that
    > may be what you're up against. As an alternative you can use
    > non-standard __COUNTER__. And the only thing that makes that compiler
    > specific information slightly on-topic here is that it's an issue with
    > Marginean's original scope guard (which is of general interest to the
    > C++ community), which needs to be modified for use with Visual C++.
    >

    Alas, __COUNTER__ is not defined in 6.0. The rest works as explained.
    Thank you so very much!
    - Ark
    Ark Khasin, Jul 15, 2007
    #9
  10. Dave Vandervies wrote:

    > MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    > it's invoked properly.


    Really? Do they have:

    - New C99 math functions like lrint, lrintf, round etc ?
    - A C99 compliant snprintf function?
    - C99 variadic macros?

    Erik
    --
    -----------------------------------------------------------------
    Erik de Castro Lopo
    -----------------------------------------------------------------
    "Circle is-a ellipse? Ellipse is-a circle? Ellipse has-a circle?"
    -- Tommy McGuire
    Erik de Castro Lopo, Jul 15, 2007
    #10
  11. Ark Khasin

    red floyd Guest

    Erik de Castro Lopo wrote:
    > Dave Vandervies wrote:
    >
    >> MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    >> it's invoked properly.

    >
    > Really? Do they have:
    >
    > - New C99 math functions like lrint, lrintf, round etc ?
    > - A C99 compliant snprintf function?
    > - C99 variadic macros?
    >


    And what do C99 functions have to do with C90 (OP spec'ed 9899:1990)
    compliance?
    red floyd, Jul 15, 2007
    #11
  12. On Jul 15, 8:37 am, "Alf P. Steinbach" <> wrote:
    > * Alf P. Steinbach:
    >


    > > * Ark Khasin:
    > >> Due to a peculiar need (code instrumentation) I came across unexpected
    > >> behavior of Visual Studio 6.0 and 2005 (doing the same thing):

    >

    [unnecessary stuff chopped off]
    > >> int main(int argc)
    > >> {
    > >> static int y=MYNUM(21); //error!


    > Just another suggestion: your "main" signature is incorrect.
    >


    Not really. The following code compiles well on comeau online:

    int main(int argc)
    {
    return 1;
    }

    I guess the standard expects the implementations to support the two
    "standard" signatures, but it also says that other signatures are
    allowed as far as return type is int:

    <quote>
    3.6.1.2:
    (main) function shall not be overloaded. It shall have a return type
    of type int, but otherwise its type is implementation-defined. All
    implementations shall allow both of the following efinitions of
    main.....
    </quote>

    -N
    Neelesh Bodas, Jul 15, 2007
    #12
  13. Ark Khasin

    Default User Guest

    Neelesh Bodas wrote:

    > On Jul 15, 8:37 am, "Alf P. Steinbach" <> wrote:
    > > * Alf P. Steinbach:
    > >

    >
    > > > * Ark Khasin:


    > > >> int main(int argc)
    > > >> {
    > > >> static int y=MYNUM(21); //error!

    >
    > > Just another suggestion: your "main" signature is incorrect.


    > I guess the standard expects the implementations to support the two
    > "standard" signatures, but it also says that other signatures are
    > allowed as far as return type is int:


    So? That just makes it non-standard extension. It is incorrect within
    the scope of either of these newsgroups.



    Brian
    Default User, Jul 15, 2007
    #13
  14. Erik de Castro Lopo wrote:
    > Dave Vandervies wrote:
    >
    >> MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    >> it's invoked properly.

    >
    > Really? Do they have:
    >
    > - New C99 math functions like lrint, lrintf, round etc ?
    > - A C99 compliant snprintf function?
    > - C99 variadic macros?


    Only the truly perverse think that "complies to ISO 9899:1990" implies
    the presence on C99 additions. In no way does their absence invalidate
    Mr. Vandervies's claim.
    Martin Ambuhl, Jul 15, 2007
    #14
  15. Neelesh Bodas said:

    <snip>

    > <quote>
    > 3.6.1.2:
    > (main) function shall not be overloaded.


    No, there is no section 3.6.1.2 in the Standard. There is a section
    3.6(1), however, which says: "byte - addressable unit of data storage
    large enough to hold any member of the basic character set of the
    execution environment". I'm not sure how this is relevant to the fact
    that your main declarator is broken.

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
    Richard Heathfield, Jul 15, 2007
    #15
  16. Ark Khasin

    Bo Persson Guest

    Erik de Castro Lopo wrote:
    :: Dave Vandervies wrote:
    ::
    ::: MSVC6 complies to ISO 9899:1990 as well as any other compiler
    ::: does when it's invoked properly.
    ::
    :: Really? Do they have:
    ::
    :: - New C99 math functions like lrint, lrintf, round etc ?
    :: - A C99 compliant snprintf function?
    :: - C99 variadic macros?

    That wasn't available in 1990, was it?


    Bo Persson
    Bo Persson, Jul 15, 2007
    #16
  17. Ark Khasin

    Bo Persson Guest

    Dave Vandervies wrote:
    :: In article <469981e9$0$30620$>,
    :: GeekBoy <> wrote:
    :::
    ::: "Ark Khasin" <> wrote in message
    ::: news:pbfmi.4059$7R4.1870@trndny09...
    :::: Due to a peculiar need (code instrumentation) I came across
    :::: unexpected behavior of Visual Studio 6.0 and 2005 (doing the
    :::: same thing):
    ::
    :: [...]
    ::
    :::: Any suggestions?
    :::
    ::: Yeah, buy a compiler that is ANSI/ISO compliant
    ::
    :: MSVC6 complies to ISO 9899:1990 as well as any other compiler does
    :: when it's invoked properly. Its C++ compiler pre-dates the last
    :: two versions
    :: of the C++ standard and I don't have any experience with newer
    :: versions, but I would be surprised if they don't at least closely
    :: approximate compliance.

    There are only two versions of the C++ standard, 1998 and 2003.

    VC6 predates both of them, which you will notice if you try some
    templated code, for example.


    Bo Persson
    Bo Persson, Jul 15, 2007
    #17
  18. Ark Khasin

    Rolf Magnus Guest

    Erik de Castro Lopo wrote:

    > Dave Vandervies wrote:
    >
    >> MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    >> it's invoked properly.

    >
    > Really? Do they have:
    >
    > - New C99 math functions like lrint, lrintf, round etc ?
    > - A C99 compliant snprintf function?
    > - C99 variadic macros?


    What does this all have to do with C90 compliance?
    Rolf Magnus, Jul 15, 2007
    #18
  19. Ark Khasin

    Rolf Magnus Guest

    Richard Heathfield wrote:

    > Neelesh Bodas said:
    >
    > <snip>
    >
    >> <quote>
    >> 3.6.1.2:
    >> (main) function shall not be overloaded.

    >
    > No, there is no section 3.6.1.2 in the Standard. There is a section
    > 3.6(1), however, which says: "byte - addressable unit of data storage
    > large enough to hold any member of the basic character set of the
    > execution environment". I'm not sure how this is relevant to the fact
    > that your main declarator is broken.


    It seems that both of you didn't notice that this thread goes to both
    comp.lang.c and comp.lang.c++. It's likely that you are talking about
    different standards.
    Rolf Magnus, Jul 15, 2007
    #19
  20. On 2007-07-15 06:41, Erik de Castro Lopo wrote:
    > Dave Vandervies wrote:
    >
    >> MSVC6 complies to ISO 9899:1990 as well as any other compiler does when
    >> it's invoked properly.

    >
    > Really? Do they have:
    >
    > - New C99 math functions like lrint, lrintf, round etc ?
    > - A C99 compliant snprintf function?
    > - C99 variadic macros?


    Of course not, he said ISO 9899:1990, that's 9 years to early.

    --
    Erik Wikström
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Jul 15, 2007
    #20
    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. Charles A. Lackman
    Replies:
    1
    Views:
    1,323
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    528
    SpamProof
    Oct 21, 2003
  3. =?Utf-8?B?ZGF2aWQ=?=

    Microsoft TreeView: Microsoft.Web.UI.WebControls.dll

    =?Utf-8?B?ZGF2aWQ=?=, Apr 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,581
    Patrick Olurotimi Ige
    Apr 11, 2005
  4. Replies:
    0
    Views:
    3,556
  5. Ark Khasin

    Is it just me or just Microsoft?

    Ark Khasin, Jul 15, 2007, in forum: C++
    Replies:
    24
    Views:
    722
    Lionel B
    Jul 16, 2007
Loading...

Share This Page