Is it just me or just Microsoft?

Discussion in 'C++' 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. 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
    #11
  12. 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
    #12
  13. 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
    #13
  14. 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
    #14
  15. 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
    #15
  16. On 2007-07-15 10:59, Bo Persson wrote:
    > 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.


    And a C standard released 1990.

    --
    Erik Wikström
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Jul 15, 2007
    #16
  17. On 2007-07-15 03:59, Ark Khasin wrote:
    > 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?


    It works fine for me in VS2005, I suggest you check your compiler options.

    --
    Erik Wikström
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Jul 15, 2007
    #17
  18. Ark Khasin

    red floyd Guest

    Bo Persson wrote:
    > Dave Vandervies wrote:

    t
    > ::
    > :: 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.
    >
    >


    However, the post is about 9899:1990, which is C90. ISO C++ is
    14882:1998 or 14882:2003.
    red floyd, Jul 15, 2007
    #18
  19. In article <j_wmi.46532$>,
    red floyd <> wrote:
    >Bo Persson wrote:
    >> Dave Vandervies wrote:

    >t
    >> ::
    >> :: 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.


    And, with only two versions, those two are the last two, and (as you
    noted) it pre-dates both of them.
    I think what I actually meant was "last two versions of the language
    definition", which would include various editions of Stroustrup as
    earlier versions. I don't know enough about either pre-standard C++
    or MSVC6's C++ compiler to comment on how well it did with that.


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

    >
    >However, the post is about 9899:1990, which is C90. ISO C++ is
    >14882:1998 or 14882:2003.


    I believe he was referring to my comment that the C++ compiler pre-dates
    the last two versions of the C++ standard. (It's also pre-dates C99,
    but Microsoft isn't doing much worse than a lot of other major compiler
    vendors on that one. (That is, Microsoft appears to be doing absolutely
    nothing about C99, and a lot of other major compilers seem to be doing
    almost nothing.))


    dave

    --
    Dave Vandervies
    I use the term "sandbox" to describe a "closed" environment,
    because it's shorter to type than "hermetically sealed".
    --infobahn in comp.programming
    Dave Vandervies, Jul 15, 2007
    #19
  20. Ark Khasin

    GeekBoy Guest

    "Ark Khasin" <> wrote in message
    news:Ssfmi.3739$yx4.1551@trndny08...
    > 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


    Then get the newest one. Visual Studio 2005, most compliant and stable yet.
    GeekBoy, Jul 16, 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,324
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    530
    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,558
  5. Ark Khasin

    Is it just me or just Microsoft?

    Ark Khasin, Jul 15, 2007, in forum: C Programming
    Replies:
    42
    Views:
    1,100
    user923005
    Jul 17, 2007
Loading...

Share This Page