-
Notifications
You must be signed in to change notification settings - Fork 6
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
implicit declaration of aligned_alloc #19
Comments
Very odd, as this is a function required by the standard. Are you sure you're using the right system headers? |
as it turns out mingw stdlib.h does not seem to have aligned_alloc, to make things more fun _aligned_malloc requires the use of _aligned_free so i cant just use a macro as a hack workaround |
Maybe build it as a DLL using a real (and static) libc and link to it? |
im not entirely sure what you want me to do, putting a declaration of aligned_alloc in build/libplum.c seems to just sort of work |
If simply adding |
i have not modified the mingw headers, it seems like they just dont declare aligned_alloc. despite that, aligned_alloc appears to work, though i have only tested that it doesnt segfault. |
You can always try a simple program like this one: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdalign.h>
void * aligned_alloc(size_t, size_t);
int main (void) {
char (* buf)[alignof(max_align_t)] = aligned_alloc(4 * sizeof *buf, 4 * sizeof *buf);
printf("buf: %p\n", buf);
if (buf) {
for (size_t p = 0; p < 4; p ++) {
memset(buf[p], 'A' + p, sizeof *buf - 1);
buf[p][sizeof *buf - 1] = 0;
}
for (size_t p = 0; p < 4; p ++) puts(buf[p]);
}
return 0;
} If this program works (as in, it prints reasonable stuff), then |
undefined reference to aligned_alloc so, looking at the only instance of aligned_alloc in the code of libplum suggest that it gets optimized out during compilation, meaning it doesnt need to actually exist in the c runtime if the alignment provided by malloc is sufficient, but recent gcc requires the function to have a prototype otherwise it refuses to compile it |
That's exactly what I was thinking. I wonder if there is a good solution to this. |
is there anything wrong with a declaration for aligned_alloc that may fail at link time, with a comment explaining what its for? the alternative is a compile-time flag to make the function fail at runtime |
It's not a general solution. It only makes sense in the nonconformant nightmare of Windows. |
when compiling libplum for windows,
aligned_alloc
is not declaredx86_64-w64-mingw32-cc (GCC) 14.2.0
treats implicit declaration as an erroraligned_alloc
appears to be declared when compiling for linuxThe text was updated successfully, but these errors were encountered: