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

Should I move printf.c and printf.h into a subdirectory? #58

Closed
eyalroz opened this issue Nov 11, 2021 · 4 comments
Closed

Should I move printf.c and printf.h into a subdirectory? #58

eyalroz opened this issue Nov 11, 2021 · 4 comments
Labels
question Further information is requested task

Comments

@eyalroz
Copy link
Owner

eyalroz commented Nov 11, 2021

The repository root has a bunch of non-source files in addition to printf.c and printf.h; this is slightly distracting and messy. In larger repositories, one typically places the sources files in (one or more) subdirectories, and none of them in the repository root.

Should we, then, create a src/source subdirectory, and movie printf.h and printf.c into it?

@eyalroz eyalroz added the question Further information is requested label Nov 11, 2021
@diggit
Copy link

diggit commented Nov 11, 2021

Larger projects usually have struture like src/printf.c and inc/projectName/printf.h. This approach allows adding of somePath/LocalSubmoduleName/inc into include path. Then you include headers with projectName path like #include "printf/printf.h" . Such system minimizes possibility of filename collisions.

But it's probably beneficial only if you want to separate headers from sources, because otherwise, header prom same directory has highest inclusion priority and there is no issue if user has some other printf.h in their include path.

@eyalroz
Copy link
Owner Author

eyalroz commented Nov 11, 2021

Larger projects usually have struture like src/printf.c and inc/projectName/printf.h.

Some put everything in src/, some separate an include/ directory. Personally, and since I separate the repo structure from the installed directory structure, I like them both under the same subdir.

This approach allows adding of somePath/LocalSubmoduleName/inc into include path.

But that's not my suggested use. If you build the library with CMake, then install it (for example, under /opt/printf), you get:

/opt/printf/
  \-- include
     \-- printf.h
  \-- lib
     \-- libprintf.so
     \-- cmake
        \-- printf
           \-- printf-config-version.cmake
           \-- printf-config.cmake
           \-- printf-config-release.cmake

and the CMake files set up the targets for you, so you don't get any collisions. If you are worried about collisions, you can install under /opt/printf/printf, and then use -I/opt/printf with #include <printf/printf.h>.

By the way - our use of printf.h is a bit "dangerous", since glibc has a file named printf.h, located in /usr/include/printf.h, and if one isn't careful, a collision is rather likely.

eyalroz added a commit that referenced this issue Nov 11, 2021
…ory (and marking it as an include directory).
eyalroz added a commit that referenced this issue Nov 12, 2021
…ory (and marking it as an include directory).
@eyalroz eyalroz added the task label Nov 30, 2021
@edubart
Copy link

edubart commented Dec 29, 2021

Both files could be merged into one, turning the library in a single header library, like nanoprintf and stb_sprintf. I think It's more easy to use single header C libraries.

@eyalroz
Copy link
Owner Author

eyalroz commented Dec 29, 2021

@edubart : Please open a separate issue for that request.

eyalroz added a commit that referenced this issue Jan 21, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Jan 22, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Jan 26, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Jan 31, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Jan 31, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Jan 31, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Feb 11, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
eyalroz added a commit that referenced this issue Feb 21, 2022
…of the source files into a library-specific subdirectory, as per #58, there is no longer the risk of clashing with glibc's `printf.h`, so the test programs can use `<foo.h>`-style inclusion rather than `"../path/to/foo.h"`-style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested task
Projects
None yet
Development

No branches or pull requests

3 participants