This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C28 - shift count is too large

cl28FP NameServerMessageQ.c ...
"NameServerMessageQ.c", line 206: warning: shift count is too large

On the C28, I have a variable that is a unsigned long (32-bits).  When I attempt to left shift the variable by 16 bits it gives the warning above.  Isn't this operation okay?  If so, why does it give me a warning?  It doesn't seem like this should be giving me a warning.

I'm buiding with version 5.2.3

Judah

  • I would not expect that warning for a left shift of 16 bits on a unsigned long. Code you provide the code snippet or C source file that generates the warning?

  • AartiG,

    Could you try something like this:

    unsigned long int id = 1;

    id = id << 16;

    I'm in the BIOS world so we have our own types which are #defined to the 'c' types.

    Judah

  • I don't get any warning with this code snippet.

    If you can preprocess your source file (compile with -ppo) so it pulls in all the header file information and attach it here, it would be helpful in identifying the source of the warning.

  • Does your code look something like this?

    unsigned long int id = 1 << 16;

    The constant "1" does not have a suffix, so it is treated as an "int", which is only 16 bits on C28x, so you would get the warning.  If this is the case, add the suffix "L" (upper or lower case) to the constant to make the compiler treat the constant as a "long int."

  • Its not exactly like it but very similar.  I think its exactly like:

    unsigned int id = 1;

    unsigned long int val = id << 16;

    In my case, id is 16-bits but val is 32-bits.  Very similar to the scenario above.  How do I  prevent the warning in this case? Since 'id' is not a constant, could I cast it as a 'unsigned long int' to prevent this warning?

  • You must cast it to "unsigned long int," or you will get the wrong value.  The expression "id << 16" is an "unsigned int" expression; first the "unsigned int" value is computed, and then that value is converted to "unsigned long int" before being assigned to "val."  In addition, because the shift count is equal to the width of the shifted type, the behavior is undefined, so that is not legal C code.