Questions about using data type aliases.

Started by
14 comments, last by _the_phantom_ 15 years, 11 months ago
Quote:Original post by grill8
I am using VC++ 6.0.
Any particular reason you're using a pre-standard compiler and IDE that's now a decade old rather than one of the brand new versions that are freely available? You mention that you're planning to use data type aliases, which implies that you've not yet started your project - why the out-of-date and broken technology?

- Jason Astle-Adams

Advertisement
No, this type of aliases is pointless - it doesn't do anything.

If you abstracted type sizes (uint32_t, or similar) to server some purpose (ensuring data sizes for serialization, then it makes sense.

But simply renaming the types into something (why j?) doesn't do anything.

Quote:be typedef'd since they do not have a specific type


They are very specifically typed. Each container defines types such as value_type, size_type, and so on. That's the types that should be used for generic programming.
IMHO, creating an alias for a base type *just* to rename the base type is irrelevant, except for adding another batch of things to maintain and remember.

I would rather create a typedef for a functionnal reason. e.g :

typedef double Coordinate


but not

typedef double MyOwnDoubleTypeDefinitionForTheWin


What you intend to do is like naming a css class (to going back to my speciality) "BoldRedText" instead of "WarningMessage" and is considered bad practice.


OpenGL do such things, and I ended up just ignoring those aliases and use plain C types instead.





Quote:3) How to consistently deal with the rampant amount of differently typedefd variable types when combining implementation of different languages. I use C/C++/GDI/DirectX and Sockets. I just need to know how to properly use so many different data types that resolve to the same thing. For example there is TRUE/FALSE as well as true/false, UINT and unsigned int, DWORD as well as int. BYTE/CHAR/char etc. It just REALLY gets out of hand to have to deal with so many data types that simply resolve to the same thing. Is there a good solution for this other than figuring out which types are the same and not etc?

You're only making this problem worse, and with no gain to yourself.

There are valid reasons for aliasing types -- one of the biggest bonuses for library code is it provides you a mechanism to guarantee data type sizes at compile time, which can be extremely useful for some libraries.

The problem with simply 'renaming' them is that you add no extra information or functionality, and in this specific case of using your types versus the 'other' renamed types, can actually break your code if you're working on cross-platform stuff (your renamed type may not sync up with the library type on all platforms; I've seen it happen and it's rather unpleasant to track down).

Renaming types for renaming's sake is generally not useful and only smacks of unwarranted code homogenization. When in Rome, use the types defined by the Romans.
Quote:Original post by jpetrie

Renaming types for renaming's sake is generally not useful and only smacks of unwarranted code homogenization. When in Rome, use the types defined by the Romans.


<offtopic>

void main() {  const uintVIII_t char;  intXXXII_t a;  intXXXII_t b;  const intVIII * text = "Hello Rome!";  std::cin >> a >> b;  std::cout << text << a << b;  // in Rome, you can't return 0;  return I;}


On second thought, in Rome, type aliasing would be justified.

</offtopic>
If you are using C++ and want to ensure type sizes then Boost has already taken care of this problem for you; clicky

This topic is closed to new replies.

Advertisement