Initializing variables of type long long

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Initializing variables of type long long

2,135 次查看
lowpy
Contributor I

I have a problem initializing variables of type long long.

 

Normally this should work:

long long x = 0x428A2F98D728AE22LL;

 but when I compile I get the following error: C2704: Illegal number

 

Is this not supported by CW compiler or am I doing something wrong ?

 

Thanks in advance!

标签 (1)
标记 (1)
0 项奖励
回复
6 回复数

1,655 次查看
Lundin
Senior Contributor IV

I believe neither the HCS08 nor the HCS12 Codewarrior supports C99. If you need to use C99 features, the first thing you should do is to get a C99 compiler.

0 项奖励
回复

1,655 次查看
BlackNight
NXP Employee
NXP Employee

Hello,

yes, 64bit integers are not supported. long long is supported with 32bit max.

Anyway, doing 64bit math with a HCS08 or HCS12 will be rather a performance bottleneck.

So if you are using a 8 or 16bit processor for 64bit math, you might use the wrong cpu for it.

 

BK

0 项奖励
回复

1,655 次查看
lowpy
Contributor I

Let me just see it I got this right.

 

Even if I manage to initialize the variable in another way, operations on that variable will only affect the lower 32 bits ?

0 项奖励
回复

1,655 次查看
bigmac
Specialist III

Hello,

 

Your variable could be treated as an array of two double words, four words, or eight bytes, or maybe a union of all three to provide greater flexibility.  Arithmetic operations would then need to be performed on the individual array elements.

 

Regards,

Mac

 

0 项奖励
回复

1,655 次查看
BlackNight
NXP Employee
NXP Employee

sizeof(long long) will return 4, means it occupies 4 bytes (32bit) in memory. You will only have 32bit available.

An alternative would be to use/implement a software library, with something like

int64_t Add64(int64_t, int64_t);

I did not check, but maybe things like that is already awailable as open source.

 

BK

0 项奖励
回复

1,655 次查看
kef
Specialist I

What if lossless 64bit computation is required one or few times per second? Even 4-bits MCU can do it.

0 项奖励
回复