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

Include <stddef.h> for size_t #404

Closed
wants to merge 26 commits into from
Closed

Conversation

notinaboat
Copy link

pigpio.h uses size_t, so it should include <stddef.h>.

https://www.gnu.org/software/libc/manual/html_node/Important-Data-Types.html

guymcswain and others added 26 commits April 30, 2020 10:04
Add link to Xojo implementation by Eugene Dakin
Removed experimental on Pi4 paragraph.
@guymcswain
Copy link
Collaborator

pigpio.h uses size_t, so it should include <stddef.h>

Not so, unless I missed the part about pigpio declaring to be ISO C compliant.

Data Type: size_t
... On systems using the GNU C Library, this will be unsigned int or unsigned long int.

@notinaboat
Copy link
Author

As it stands, pigpio.h gets the definition of size_t by including <pthread.h> (this includes <sched.h> which then includes <stddef.h>).

I'm not sure that ISO C or not really matters, it's just that its better to include the header that defines the type being used rather than rely on it being indirectly defined by pthread.

(Context: i'm passing pigpio.h to a libclang based wrapper generator to generate Julia bindings. The clang environment includes standard C headers, but not OS headers (like pthread). I can work around this easily enough, but the patch in this PR just seems like the "right way").

If stddef.h is not included, size_t is undefined. e.g.

pi@raspberrypi:/tmp $ cat foo.c
size_t x = 3;
pi@raspberrypi:/tmp $ gcc -c foo.c
foo.c:1:1: error: unknown type name ‘size_t’
 size_t x = 3;
 ^~~~~~
foo.c:1:1: note: ‘size_t’ is defined in header ‘<stddef.h>; did you forget to ‘#include <stddef.h>’?

@guymcswain
Copy link
Collaborator

Ok, that makes sense. Thanks.

@guymcswain guymcswain changed the base branch from master to develop November 6, 2020 13:34
@guymcswain
Copy link
Collaborator

@notinaboat , I tried to edit this PR to merge it into the develop branch but it looks like that creates a ton of commits and I'm not sure why. Can you make sure your fork is up to date then re-submit the PR against the develop branch?

@notinaboat
Copy link
Author

Hi @guymcswain, maybe its easier for you to just paste #include <stddef.h> into pigpio.h in your branch and close this PR? I'm not sure why the other commits are showing up in this PR. Probably my fault for basing my branch on master.

@guymcswain
Copy link
Collaborator

Merged in v79

@guymcswain guymcswain closed this Mar 2, 2021
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

Successfully merging this pull request may close these issues.

None yet

5 participants