4

I am dealing with libpcap and nginx source codes these days. I wonder something like:

  1. In libpcap, they use their own unsigned int type bpf_u_int32
  2. In nginx, they use their own unsinged int type ngx_int_t as well

what's the advantage of these usages compared with built-in types?

VBart
  • 14,714
  • 4
  • 45
  • 49
PigeonLueng
  • 73
  • 1
  • 5

1 Answers1

3

Generally it's about controlling complexity. Some code bases need to be run across multiple platforms. Sometimes the reason is that the code evolves to encompass more platforms, while in other cases the code starts from the premise that it needs to run on multiple platforms.

Anyway, a good architectural pattern is to lower dependencies to other systems/libraries/platforms/compilers etc. This allows the platform dependant code to kept in small place and not permeated across the whole code base.

Thus when you move the code to a new platform the amount of code that needs rework is kept smaller.

All in all it's about the cost of maintainability, and it isn't a magic bullet, rather it's a proven architectural pattern.

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216