Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol name clash #2490

Closed
bart9h opened this issue May 24, 2022 · 6 comments
Closed

Symbol name clash #2490

bart9h opened this issue May 24, 2022 · 6 comments

Comments

@bart9h
Copy link

bart9h commented May 24, 2022

Raylib uses generic names like Font, Music, Sound, Shader, Model, Texture, BoundingBox, Matrix, BeginDrawing, PlaySound, etc. These names could also be used in anywhere, and should be avoided in a library, because it can lead to clashes. There are other (mostly closed) issues here about compilation errors that are caused by this.

C++ has namespaces, but as raylib is written in C, maybe you should consider using a prefix for all the names in the library? Maybe raylib_, Ray_ or something like that.

For backward compatibility maybe provide an header file that does #define SomeName Ray_SomeName.

@raysan5
Copy link
Owner

raysan5 commented May 24, 2022

I'm afraid this is a know issue and can be avoided not including raylib in the same compilation unit as other libraries with colliding symbols. I have no plans to change raylib for the moment.

@raysan5 raysan5 closed this as completed May 24, 2022
@orcmid
Copy link
Contributor

orcmid commented May 24, 2022

@bart9h : For backward compatibility maybe provide an header file that does #define Ray_SomeName SomeName.

Did you mean #define SomeName Ray_SomeName? Either way, I don't think it eliminates clashes with the undecorated name.

I don't know any solution to this at the Native C Language level beyond following Ramon's advice on isolation of dependencies via compile-unit separation.

@bart9h
Copy link
Author

bart9h commented May 25, 2022

Did you mean #define SomeName Ray_SomeName?

Yes, I did.

@spillz
Copy link

spillz commented Dec 18, 2023

I think the current C naming scheme is unfortunate. Using a common and short prefix like rl would both avoid name clashes with user code and would be an important readability and discoverability win (e.g., in any decent IDE you would type rl and be prompted with available Raylib symbols). Most popular modern open source C libraries follow this practice.

But someone who really wants this now could presumably create a prefixed C wrapper in a .c file that redefines all the symbols with prefixed names and an accompanying prefixed header that would essentially hide the unprefixed names in user code that only includes the prefixed header. That's an untested proposition but would perhaps offer a migration path should you reconsider @raysan5.

@raysan5
Copy link
Owner

raysan5 commented Dec 18, 2023

@spillz no plans to add prefixes to raylib. Most collisions can be easely avoided.

@spillz
Copy link

spillz commented Dec 18, 2023

Thanks for clarifying because your "for the moment" at the end of the prior comment appeared to be leaving the door open. I am not so concerned about collisions at the machine level, just in the old brain box, so this is a blocker for me using this as a C lib. Fine though for python etc languages where namespaces are automatically defined at the package/module level. But this is your lib and you choice, tastes vary etc. so you won't get further argument from me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants