T
TimC
g++ 4.x -pedantic doesn't allow me to do this:
static const long int DOME_WANDER = int(TcsAbsDomeToArcsec*1.25/TcsIncDomeToArcsec);
(minimal code is below)
in a class declaration, and gives:
In file included from TcsEncoderTask.C:232:
AbsIncPositionTracker.h:189: error: floating-point literal cannot appear in a constant-expression
First off, is that truly illegal code (TcsAbsDomeToArcsec and
TcsIncDomeToArcsec are just #defines of floats) according to the
standards?
And secondly, if this is truly illegal and not just a mundane bug in
gcc, tell me, what would be the point of illegalising that, and what
do I do to get around it? Surely a cast (it's been a while since I've
done C/C++, so I tried several different casts, none of which worked)
is sufficient to convince both a compiler and a language lawyer that
yes, I know it's a float, but an int is perfectly acceptable for my
purposes? Initialising DOME_WANDER to be a pure int not calculated
from those above floats would be fragile and a serious pain.
Absolutely minimal code:
#define TcsIncDomeToArcsec 0.150
class AbsIncPositionTracker {
static const long int DOME_WANDER = (long int)(TcsAbsDomeToArcsec*1.25/TcsIncDomeToArcsec);
};
int main (int, char**)
{
return 0;
}
asd.C:6: error: floating-point literal cannot appear in a constant-expression
asd.C:6: error: floating-point literal cannot appear in a constant-expression
asd.C:6: error: floating-point literal cannot appear in a constant-expression
static const long int DOME_WANDER = int(TcsAbsDomeToArcsec*1.25/TcsIncDomeToArcsec);
(minimal code is below)
in a class declaration, and gives:
In file included from TcsEncoderTask.C:232:
AbsIncPositionTracker.h:189: error: floating-point literal cannot appear in a constant-expression
First off, is that truly illegal code (TcsAbsDomeToArcsec and
TcsIncDomeToArcsec are just #defines of floats) according to the
standards?
And secondly, if this is truly illegal and not just a mundane bug in
gcc, tell me, what would be the point of illegalising that, and what
do I do to get around it? Surely a cast (it's been a while since I've
done C/C++, so I tried several different casts, none of which worked)
is sufficient to convince both a compiler and a language lawyer that
yes, I know it's a float, but an int is perfectly acceptable for my
purposes? Initialising DOME_WANDER to be a pure int not calculated
from those above floats would be fragile and a serious pain.
Absolutely minimal code:
#define TcsAbsDomeToArcsec (10.5469 * 60.0)cat asd.C
#define TcsIncDomeToArcsec 0.150
class AbsIncPositionTracker {
static const long int DOME_WANDER = (long int)(TcsAbsDomeToArcsec*1.25/TcsIncDomeToArcsec);
};
int main (int, char**)
{
return 0;
}
asd.C:6: error: floating-point literal cannot appear in a constant-expressiong++ -c -ansi -Wall -W -pedantic asd.C
asd.C:6: error: floating-point literal cannot appear in a constant-expression
asd.C:6: error: floating-point literal cannot appear in a constant-expression
asd.C:6: error: floating-point literal cannot appear in a constant-expression