Variable name...

Discussion in 'C++' started by Denis Remezov, May 24, 2004.

  1. Il Maestro wrote:
    >
    > Greetings to everyone, this is my odd (probably trivial) question:
    > i defined that thing, like gobal var
    > ...
    > int y1 = 0;
    > ...
    > and at compile time i got
    > ...
    > C:\Dati\Luigi\Progetti\provec++\plasma\SetPixel.cpp(42) : error C2373: 'y1'
    > : redefinition; different type modifiers
    > c:\programmi\microsoft visual studio\vc98\include\math.h(435) : see
    > declaration of 'y1'
    > ...
    > then looked at the corresponding line in math.h, that is
    > ...
    > _CRTIMP double __cdecl y1(double);
    > ...
    > And i dont have any math.h include around.
    > Any hint? I'm under VC6, if it helps...
    > Thank to everyone who will reply me.
    > Luigi.


    Bessel functions j0, j1, jn, y0, y1, yn are quite common, not only
    with MS libraries. Some other header included <math.h>, where they
    were declared; e.g., <iostream> does that for me.

    It pays to just avoid using simple short names like the above in the
    /global scope/ (actually, any names if there is no good reason to the
    contrary). Put them into a namespace; an unnamed namespace if you
    only need them in a given unit.

    Denis
     
    Denis Remezov, May 24, 2004
    #1
    1. Advertising

  2. Denis Remezov

    Il Maestro Guest

    Greetings to everyone, this is my odd (probably trivial) question:
    i defined that thing, like gobal var
    ....
    int y1 = 0;
    ....
    and at compile time i got
    ....
    C:\Dati\Luigi\Progetti\provec++\plasma\SetPixel.cpp(42) : error C2373: 'y1'
    : redefinition; different type modifiers
    c:\programmi\microsoft visual studio\vc98\include\math.h(435) : see
    declaration of 'y1'
    ....
    then looked at the corresponding line in math.h, that is
    ....
    _CRTIMP double __cdecl y1(double);
    ....
    And i dont have any math.h include around.
    Any hint? I'm under VC6, if it helps...
    Thank to everyone who will reply me.
    Luigi.
     
    Il Maestro, May 24, 2004
    #2
    1. Advertising

  3. Denis Remezov

    Gregg Guest

    "Il Maestro" <> wrote in
    news:EHfsc.234044$:

    > Greetings to everyone, this is my odd (probably trivial) question:
    > i defined that thing, like gobal var
    > ...
    > int y1 = 0;
    > ...
    > and at compile time i got
    > ...
    > C:\Dati\Luigi\Progetti\provec++\plasma\SetPixel.cpp(42) : error C2373:
    > 'y1'
    >: redefinition; different type modifiers
    > c:\programmi\microsoft visual studio\vc98\include\math.h(435)
    > : see
    > declaration of 'y1'
    > ...
    > then looked at the corresponding line in math.h, that is
    > ...
    > _CRTIMP double __cdecl y1(double);
    > ...
    > And i dont have any math.h include around.
    > Any hint? I'm under VC6, if it helps...
    > Thank to everyone who will reply me.
    > Luigi.


    According to the documentation for VC7 (I don't have VC98, that is pretty
    old for a C++ compiler), the functions _y0, _y1, and _yn(all with leading
    underscores) compute Bessel functions. My copy of math.h shows these
    functions both with and without leading underscore, depending on various
    preprocessor definitions. I am not sure what exactly controls which is
    selected, but maybe this will provide you with some insight.

    Gregg
     
    Gregg, May 24, 2004
    #3
  4. "Il Maestro" <> wrote in message
    news:EHfsc.234044$...
    > Greetings to everyone, this is my odd (probably trivial) question:
    > i defined that thing, like gobal var
    > ...
    > int y1 = 0;
    > ...
    > and at compile time i got
    > ...
    > C:\Dati\Luigi\Progetti\provec++\plasma\SetPixel.cpp(42) : error C2373:

    'y1'
    > : redefinition; different type modifiers
    > c:\programmi\microsoft visual studio\vc98\include\math.h(435) :

    see
    > declaration of 'y1'
    > ...
    > then looked at the corresponding line in math.h, that is
    > ...
    > _CRTIMP double __cdecl y1(double);
    > ...
    > And i dont have any math.h include around.
    > Any hint? I'm under VC6, if it helps...
    > Thank to everyone who will reply me.
    > Luigi.
    >


    VC6 only turns these names on if you have a macro defined, OLDNAMES I think
    it is. So look at your compiler settings and turn that off if its on.

    My memory might be playing tricks on me so if that isn't right ask in VC
    group, for instance news:microsoft.public.vc.language

    john
     
    John Harrison, May 24, 2004
    #4
  5. Denis Remezov

    John Carson Guest

    "John Harrison" <> wrote in message
    news:
    >
    > VC6 only turns these names on if you have a macro defined, OLDNAMES I
    > think it is. So look at your compiler settings and turn that off if
    > its on.
    >
    > My memory might be playing tricks on me so if that isn't right ask in
    > VC group, for instance news:microsoft.public.vc.language



    Header files are a pain in the neck to interpret in terms of #ifdefs and
    such, but it appears that y1 and the rest typically ARE defined.

    The main case in which this is NOT true is when the /Za (disable extensions)
    compiler switch is set AND it is a C file that is being compiled.

    If it is a C++ file, then (with or without /Za) y1 is defined and the
    problem arises. It seems that the only practical solution is to NOT have a
    variable named y1 (or y0 or yn or a few other things) at global scope.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
     
    John Carson, May 24, 2004
    #5
  6. Denis Remezov

    Il Maestro Guest

    Ok, i got the point...
    I think i'll follow the namespace advice, because i find ilarious i cant use
    such a useful name....
    Thank to everyone ;)
     
    Il Maestro, May 24, 2004
    #6
  7. Old Wolf wrote:
    >
    > Denis Remezov <> wrote:
    > >
    > > Bessel functions j0, j1, jn, y0, y1, yn are quite common, not only
    > > with MS libraries. Some other header included <math.h>, where they
    > > were declared; e.g., <iostream> does that for me.

    >
    > <iostream> ought to only include <cmath> (or not include either, of course).
    > If you get y1 in the global namespace as a result of including iostream,
    > then a compiler upgrade is probably in order.
    >


    Yes that was what happened. On the hand, y1 is not a standard function,
    so placing it in the std namespace would not be the right thing, I assume.

    Denis
     
    Denis Remezov, May 24, 2004
    #7
  8. Denis Remezov

    Old Wolf Guest

    Denis Remezov <> wrote:
    >
    > Bessel functions j0, j1, jn, y0, y1, yn are quite common, not only
    > with MS libraries. Some other header included <math.h>, where they
    > were declared; e.g., <iostream> does that for me.


    <iostream> ought to only include <cmath> (or not include either, of course).
    If you get y1 in the global namespace as a result of including iostream,
    then a compiler upgrade is probably in order.

    (Add this one to the list of reasons not to go "using namespace std;")
     
    Old Wolf, May 24, 2004
    #8
    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. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    835
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,827
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,402
    Joe Smith
    Apr 22, 2007
  4. mfglinux
    Replies:
    11
    Views:
    710
    Roberto Bonvallet
    Sep 12, 2007
  5. David Filmer
    Replies:
    19
    Views:
    248
    Kevin Collins
    May 21, 2004
Loading...

Share This Page