3

Please help me understand reason of defining C types in some projects.

In my current company I found that someone made definitions of types that are equivalent of those that are already defined in <stdint.h>.

Such approach makes harder to integrate 3party code into project, and makes programmer work, bit more frustrating.

But I can also see that some projects, like gnome do the same. There is a gchar, gsize, and gint32 for example.

Because I don't see ANY reason for such approach, I kindly ask for explanation.

What is the reason that <stdint.h> isn't sufficient.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78
wiesniak
  • 558
  • 2
  • 11

2 Answers2

4

This is not good practice. It only leads to less compatibility and portability. I don't see any reason that it should be done. stdint.h exists to avoid this.

Thomas Jager
  • 4,836
  • 2
  • 16
  • 30
2

<stdint.h> was standardized in C99. Perhaps the codebase predates <stdint.h>, or it needs to compile on platforms that don't have it. It was an extremely common thing to do in C89 and K&R C when there were no portable fixed size typedefs. Even modern projects may keep around these compatibility shims if they still aim to be compilable on decades-old platforms.

In my current company I found that someone made definitions of types that are equivalent of those that are already defined in <stdint.h>.

If your codebase targets C99 or later then there's no need.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578