From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Hick Gunter

>>>Integer promotion is usually ok between integers of the same signedness.

For some definition of 'OK'.

>>>However, in
        unsigned char uns = 0xff;
        long val = uns;
>>>what should be the (32 Bit size assumed) value of val? Should it be 
>>>0x000000ff (promotion before conversion) or 0xffffffff (promotion after 
>>>conversion)? Or flagged as "assignment between variables of different 
>>>signedness"?

The standard is clear about this case (as it is about nearly all cases). Value 
is always preserved in integer promotion if possible. The value is simply 255 
in any integer large enough to hold it.

>>>Or for example, how often is the loop executed?
        uint16_t count = 0xffff;
        int16_t ii;
        for (ii = 0; II < count, ii++) { ... }

>>> Integer demotion (i.e. copying a value from a larger size to a smaller size 
>>> integer) should be flagged by the compiler (unless the compiler is clever 
>>> enough to figure out that the value cannot be out of range).

The standard does not define 'demotion'. This loop will not terminate because 
incrementing the loop variable will cause integer overflow (usually ignored) 
and the test will always be true. The conversions for the test preserve value.

>>>        long val = 0x65;
        char xxx = val;

Valid C, but typically causes a warning.

>>>However

        struct mystruct *ptr1 = '\0';
        struct mystruct *ptr2 = 0;

>>>is "making a pointer from an integer of a different size without a cast" 
>>>(the first on all architectures, the second on LP64 architectures).

I have no idea what you intend by this, but this too is valid C. No warnings.

>>>Of course this is nitpicking and the examples are trivial, but compilers 
>>>need to guess if the programmer is just being stupid or downright 
>>>brilliant...

I'm still waiting for the nits. The C/C++ standards are written precisely to 
cover these and other things that those maintaining mature source code really 
care about.

Regards
David M Bennett FACS

Andl - A New Database Language - andl.org





_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: h...@scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to