Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Variable name...

Reply
Thread Tools

Variable name...

 
 
Denis Remezov
Guest
Posts: n/a
 
      05-24-2004
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.cp p(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
 
Reply With Quote
 
 
 
 
Il Maestro
Guest
Posts: n/a
 
      05-24-2004
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.cp p(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.



 
Reply With Quote
 
 
 
 
Gregg
Guest
Posts: n/a
 
      05-24-2004
"Il Maestro" <(E-Mail Removed)> wrote in
news:EHfsc.234044$(E-Mail Removed):

> 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.cp p(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
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      05-24-2004

"Il Maestro" <(E-Mail Removed)> wrote in message
news:EHfsc.234044$(E-Mail Removed)...
> 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.cp p(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


 
Reply With Quote
 
John Carson
Guest
Posts: n/a
 
      05-24-2004
"John Harrison" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
>
> 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)

 
Reply With Quote
 
Il Maestro
Guest
Posts: n/a
 
      05-24-2004
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


 
Reply With Quote
 
Denis Remezov
Guest
Posts: n/a
 
      05-24-2004
Old Wolf wrote:
>
> Denis Remezov <(E-Mail Removed)> 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
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      05-24-2004
Denis Remezov <(E-Mail Removed)> 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;")
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
how to implement variable ports with variable width? weijun VHDL 4 12-19-2005 05:16 PM
Variable 'variable lengths' Taras_96 VHDL 2 05-09-2005 12:58 AM
Convert Character Variable to Integer Variable Brad Smallridge VHDL 2 11-18-2004 01:56 AM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments