Variable name...

D

Denis Remezov

Il said:
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
 
I

Il Maestro

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.
 
G

Gregg

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
 
J

John Harrison

Il Maestro said:
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
john
 
J

John Carson

John Harrison said:
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.
 
I

Il Maestro

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 ;)
 
D

Denis Remezov

Old said:
<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
 
O

Old Wolf

Denis Remezov said:
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;")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top