dcbingaman
- Joined Jun 30, 2021
- 941
I have ran into this myself multiple times when dealing with vendor 'libraries'. Name clashing during compilation and very difficult to troubleshoot and or correct. It would be nice to see namespaces added to the ANSI C standard. Most of the time I end up making very specific function names in libraries just to avoid this problem:A namespace is nothing more than a means of defining a naming hierarchy.
Without a namespace a function called reset_device must be called literally as reset_device and creating another function named reset_device (say for a different kind of device) has to be given a different name like reset_other_device.
With a namespace you can give these a prefix and if the prefix is different then the functions can in fact have an identically spelled name, this shows you the principle:
There's really nothing more to them than that, rather simple but hugely helpful, C has no namespace capability and although one can "simulate" it that requires all kinds of boiler plate code and structuring, having them designed into the language is far better, simpler and cheaper.Code:namespace Hardware namespace ADC procedure reset_device (device_ptr); // code end; end; namespace GPS procedure reset_device (device_ptr); // code end; end; end; procedure main(device_ptrs); dcl device_ptrs(2) pointer; call Hardware.ADC.reset_device(device_ptrs(ADC_DEVICE)); call Hardware.GPS.reset_devuce(device_ptrs(GPS_DEVICE)); end;
void EEPROM2237_Init(void);
void EEPROM2237_Write(...);
etc.
Very annoying.