Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

global typedef C++

This topic is 3658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is there any way to do a typedef thats in every file u create without havin to include a header each time... i want to replace "unsigned int" with just "uint"

Share this post


Link to post
Share on other sites
Advertisement
No. typedefs support normal scope and visibility rules.

If you want numeric type typedefs and you compiler is C99 compliant, then #include <stdint.h>

Share this post


Link to post
Share on other sites
Review how C++ compilation process works.

Pre-processor goes through the file line by line, expanding defines. Once done, the file is actually compiled.

There is no other meta information that would magically give compiler some insight. typedefs, unlike symbols available to linker, are source-level only.

Share this post


Link to post
Share on other sites
If you're using gcc, you can use the -D flag to tell the preprocessor to make a particular substitution. Eg:

g++ -Duint=unsigned int -c source.cpp

I may not have got the syntax for that quite right, but you get the idea. Other compilers probably have some option for this as well.

I don't think this is a particularly good idea though. Remember code is used for communication to other programmers as well, and this kind of thing will elicit a WTF? response.

<edit> just tried it out, gcc didn't like the 2-word define, it should be:
g++ -Duint=unsigned -c source.cpp

Share this post


Link to post
Share on other sites
A less WTF of doing it is to create a global header like "types.h" and place the typedefs there. There is a compiler option to force include a header in each file. For GCC it's "-include".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!