I am porting a large 3D graphics engine from windoze to linux on eclipse
environment,
and have a few C syntax problems that are over my head. At the moment I am
just
compiling the code to make a 32-bit executable, but I assume 64-bit will be
the same.
-----
1: From an original software package I wrote long ago in another language,
I could
declare the value of an f64 AKA "double" precision floating point constant
with:
$$PI = 0d400921FB54442D18
where the "0d" prefix says "this is a double precision value input in
hexadecimal".
I have about 200 of these, because I was able to compute bit-accurate values
for many fundamental math constants, and found that assigning ascii-decimal
values to the constant often led to 2~5 bit errors (in the ascii->double
code).
While that's very nice, I assume C simply does not provide such a nice
feature.
So, my question is --- what alternatives can the gurus out there come up
with.
The crappy "solution" in the windoze version of my 3D engine is the
following:
const s64 MATH_bit_PI = 0x400921FB54442D18;
const f64 MATH_PI = (*(f64*)&MATH_bit_PI);
Though this is truly revolting, it works on the windoze visual studio
compilers.
Yes, I have typedefs that define s64 and f64 from the long conventional
names.
-----
2: From a linux C header file that I created a few years ago --- that I am
fairly
sure used to compile properly --- the following generate warnings and
errors:
typedef union vec004_64 {
f64 af64[4];
struct {
f64 x, y, z, w;
};
struct {
f64 m00, m01;
f64 m10, m11;
};
} __attribute__ ((aligned(16))); // warning displayed on this line
//
// the warning says: "useless storage class specifier in empty declaration"
// the above happens on every single similar declaration in the file
//
// then, down further, i get errors (not warnings) on every line like this:
//
typedef vec004_64 f64vec4; // error displayed on this line
typedef vec004_64 f64mat2x2; // error displayed on this line
//
// the errors say: "expected '=', ',', ';', 'asm' or '__attribute__'
before f64vec4
I am confused. I remember not being familiar with the __attribute__ syntax
when
I found it years ago --- but at least it compiled and worked back then.
-----
3: Here is more code that used to compile and work (and does on windoze):
const u08 MATH_AXIS_SHIFT_1 = 0x04;
const u08 MATH_AXIS_SHIFT_2 = 0x08;
const u08 MATH_AXIS_X = 0x01;
const u08 MATH_AXIS_Y = 0x02;
const u08 MATH_AXIS_Z = 0x04;
const u08 MATH_AXIS_A = 0x08;
//
// the above lines compile okay, but the following do not (these are 7 of
about 40 lines)
//
const u16 MATH_AXIS_0X = (MATH_AXIS_X << MATH_AXIS_SHIFT_1);
const u16 MATH_AXIS_0Y = (MATH_AXIS_Y << MATH_AXIS_SHIFT_1);
const u16 MATH_AXIS_0Z = (MATH_AXIS_Z << MATH_AXIS_SHIFT_1);
const u16 MATH_AXIS_00X = (MATH_AXIS_X << MATH_AXIS_SHIFT_2);
const u16 MATH_AXIS_XY = (MATH_AXIS_X | (MATH_AXIS_Y <<
MATH_AXIS_SHIFT_1));
const u16 MATH_AXIS_XYZ = (MATH_AXIS_X | (MATH_AXIS_Y << MATH_AXIS_SHIFT_1)
| (MATH_AXIS_Z << MATH_AXIS_SHIFT_2));
//
// the errors say: "initializer element is not constant". I beg to differ
!!!
//
// the "u08" is just a typedef for "unsigned char/byte"
// the "u16" is just a typedef for "unsigned short"
-----
I'll stop here for now. Some other errors will vanish when these are fixed.
I will appreciate whatever help you can give. Thanks.
--
View this message in context:
http://www.nabble.com/64-bit-constants-tp15108100p15108100.html
Sent from the C-prog mailing list archive at Nabble.com.