yoni
yoni

Reputation: 1364

Define the default int to unsigned int

How can I (if I can) set the default int variable (in a specific program) to be unsigned int?

I mean that if int is written in the program, the compiler treats it like unsigned int.

My compiler is gcc 4.6.2

EDIT: I am not authorized to touch the code.

Upvotes: 0

Views: 7312

Answers (2)

dreamlax
dreamlax

Reputation: 95365

You can't change the default signedness of int because it is by definition a signed type (§6.2.5/4). Consider the main function which must return type int (§5.1.2.2.1/1), if you change the default signedness somehow, then main will return unsigned int, and this will cause undefined behaviour, rendering your entire application relatively useless.

You can't create a macro, because if int expands to unsigned int, then if you have declared unsigned int somewhere, you will end up with unsigned unsigned int, which is not a valid type.

Upvotes: 3

rubenvb
rubenvb

Reputation: 76785

A super-evil

#define int unsigned int

could work, but is definitely not Standard compliant and you might need to make your compiler be less strict (which is a bad thing).

Other things you can do is find and replace all occurrences of int (without a preceding unsigned) and replace those with my_typedefed_int and add a

typedef unsigned int my_typedefed_int

Which is Standard compliant but is more involved and might not be possible.

Upvotes: 3

Related Questions