Skip to main content
gamedev.net
🔒 Locked

typedef

Started by hewhay May 20, 2003 at 8:44 PM 5 replies 800+ views
Original Post
hewhay
hewhay
If I do :
    
typedef unsigned char uint8;

uint8 a, b, c;

...

c = a + b;

    
Will this give me any complication? Will the char be casted into int's, added and casted back to char? Dont't tell me to use a ms equivalent. I'm just messing around [edited by - hewhay on May 20, 2003 9:49:08 PM] [edited by - hewhay on May 20, 2003 9:50:25 PM]
humanity will always be slaved by its ignorance
chiuyan
chiuyan
compile it.

i see no reason why it wouldn''t compile, and i see no reason why anything would need to be casted to an int for it to work either.

antareus
antareus
quote:
Original post by hewhay
Will this give me any complication?

No, typedef''s are simply synonyms.
quote:
Will the char be casted into int''s, added and casted back to char?

No, there are no ints in the expression.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Way Walker
Way Walker
I''d have to check, but I''m fairly certain that when you do arithmetic on chars (and shorts?) they are "promoted" to int and then converted back. I don''t know assembly, but I think this pretty much amounts to the processor not doing anything special. It just has to behave "as if" it happened that way.

(by the way, C99 now has intN_t and uintN_t typedefed in stdint.h where N is some number of bits. Which N are available depends on your compiler. It does require
int_least8_t
int_least16_t
int_least32_t
int_least64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
Where the type is as close to N bits without going under, and
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t
uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
Where the type is the "fastest" type with at least N bits)
hewhay
hewhay
do you know if those typedef''s will be added to c++? csdtdint maybe?
humanity will always be slaved by its ignorance
antareus
antareus
quote:
Original post by hewhay
do you know if those typedef''s will be added to c++? csdtdint maybe?

They will in the next version of C++, dubbed C++0x. Don''t hold your breath for it though.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Way Walker
Way Walker
quote:
Original post by hewhay
do you know if those typedef's will be added to c++? csdtdint maybe?


I don't know, but if your compiler supports both C++ and C99 you should be able to #include <stdint.h> without problem (I really doubt they'd change the typedefs. In fact, mingw (gcc in general?) just #includes the <*.h> version in the headers.)

Edit: heheh, it's kind of like you're using C as a better C++

[edited by - Way Walker on May 21, 2003 11:18:49 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.