简体   繁体   中英

Shift left and cast with float in C

The compiler display an error when it compiles this line :

float Data;
unsigned long Valeur;
Data = - (1 << 2 - (Float_t)Valeur) * 2.135;

This is the message:

error: illegal type(s): int '<<' float

I did not find the error? Can you help me?

The expression

- (1 << 2 - (Float_t)Valeur) * 2.135;

is interpreted as

- (1 << (2 - (Float_t)Valeur)) * 2.135;

and the type of 2 - (Float_t)Valeur) is Float_t , which I assume is float or similar. You cannot shift by a floating point number.

Assuming the non-standard Float_t is typedef 'd to float or equivalent, this:

Data = - (1 << 2 - (Float_t)Valeur) * 2.135;
                       ^
                       |
                      bad!

Is the problem. The above computes 2 - (Float_t) Valeur , then uses the (floating-point!) result to shift. Perhaps you meant

Data = -((1 << 2) - (Float_t) Valeur) * 2.135;

or something. It's hard to be sure, it's quite strange code.

Valeur未初始化,并且<<优先级低于- ,也许您正在寻找:

Data = - ((1 << 2) - (Float_t)Valeur) * 2.135;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM