warning: conversion to long may sign-extend incorrectly 
Author Message
 warning: conversion to long may sign-extend incorrectly

Here are the relevant lines:

    68   unsigned long d; /* neuronenabstand */

    72   unsigned int i_max;
    73   unsigned int j_max; /* koordinaten der max. erregung */

    76   unsigned int i;
    77   unsigned int j; /* koordinaten der akt. neurons */

   112     d = (i_max - i)*(i_max - i) + (j_max - j)*(j_max - j);

So what does the compiler warn me before? I think casting from
unsigned int to unsigned long must not reach to any troubles,
as unsigned long is a superset of unsigned int. Or do I miss
something?

Hans Friedrich *who hopes that this is a comp.lang.c question* Steffani

--
Hans Friedrich Steffani
Institut fuer Elektrische Maschinen und Antriebe
TU Chemnitz-Zwickau



Mon, 26 May 1997 16:47:30 GMT  
 warning: conversion to long may sign-extend incorrectly

Quote:
> So what does the compiler warn me before? I think casting from
> unsigned int to unsigned long must not reach to any troubles,

    What warning is the compiler giving you? It may be warning that
    the intermediate calculations are not promoted to unsigned long
    until their value is assigned to d. So (...)*(...) still produces
    an unsigned int, which may not be what you're expecting.

Quote:
> Hans Friedrich *who hopes that this is a comp.lang.c question* Steffani

--

***             Count Templar, ELITE, Cobra Mk III (FM-287)             ***


Tue, 27 May 1997 02:17:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Conversion of signed long int to n-bit signed int and vs vs

2. Hi-tech C compiler : implicit signed to unsigned conversion (warning)

3. Warning C4063 incorrectly given

4. Sign extending with making unsigned int from char

5. Conversion may lose significant digits

6. "Conversion may lose significant digits..."

7. "Conversion may lose significant digits..."

8. signed longs

9. warning C4018: '<=' : signed/unsigned mismatch

10. Warnings concerning comparison of signed and unsigned variables

11. char size (was long long long long long int)

12. Signed and Unsigned Conversions

 

 
Powered by phpBB® Forum Software