benhoyt / inih

Simple .INI file parser in C, good for embedded systems
Other
2.46k stars 492 forks source link

strncpy0 should be in ini_ namespace #163

Closed WickedSmoke closed 9 months ago

WickedSmoke commented 9 months ago

My current project has a similarly named re-implementation of strncpy, so there was a compiler declaration error. Adding an "ini_" prefix to the three lines where the strncpy0 symbol is used fixed the problem, but it would be nice if ini.c was a bit more isolated out of the box.

benhoyt commented 9 months ago

Doesn't the fact that it's marked static mean it's only accessible from that file, and so shouldn't cause name collisions? Similar for the rstrip and lskip helper functions -- they're also marked static.

WickedSmoke commented 9 months ago

ini.c is being included in another module. This allows inih to be used and all the option macros to be set without touching the make files.

benhoyt commented 9 months ago

I'd rather not make changes here -- ini.c is intended to be a separate compilation unit, not included, otherwise static kind of becomes meaningless. If you'd like to do amalgamation or https://en.wikipedia.org/wiki/Single_compilation_unit type stuff, unfortunately you're on your own. If you want, you could use #define strncpy0 ini_strncpy0 before the include, and #undef strncpy0 after -- that might work.

WickedSmoke commented 9 months ago

Using the same namespace for both internal & public symbols doesn't add any complexity or risk, so it seems a rather arbitrary decision to not allow the code to be used in a wider variety of environments.

I'll just have to maintain my own fork of the code.

benhoyt commented 9 months ago

Perhaps it's arbitrary. I just don't like the additional verbosity imposed for static / internal function names. That said, I'm not super-strongly opposed to it, but would like to see if or how other projects handle this. Can you point me to some respectable C projects that do what you're suggesting for static / internal names? (I've been out of the C world proper for a while.)

WickedSmoke commented 9 months ago

I'm not here to twist your arm, but thanks for considering it.

The stb project is a popular set of single-file libraries. So looking at stb_image.h as an example, I see every static function has an "stbi__" prefix (double underbars even). Not every file in the library takes such precautions but most do.

WickedSmoke commented 9 months ago

Another example is ImGui where in imgui_internal.h every static function has an "Im" prefix.

benhoyt commented 9 months ago

Okay, you've twisted my arm. :-) This won't hurt, and it's not as ugly as I thought it might be, so I'll merge this in #164.