Problem including util.h at compile time
macOS Serra 10.12.6, Xcode 9. The following code compiles with warnings:
#include <stdio.h>
#include <util.h>
FILE * in;
char * line;
size_t len = 0;
size_t lineno = 0;
/* This program segfaults without this declaration. */
/*char *fparseln(FILE *, size_t *, size_t *, const char[3], int);*/
int main() {
in = fopen("testfile.txt", "r");
while((line = fparseln(in, &len, &lineno, NULL, 0)) != NULL) {
printf("%zu:len=%zu %s\n", lineno, len, line);
}
fclose(in);
return 0;
}
$ cat testfile.txt
this is line one
this is line two
this is line three
wow..linefour
$ gcc -I/usr/include -o chk_fparseln chk_fparseln.c
chk_fparseln.c:15:19: warning: implicit declaration of function 'fparseln' is invalid in C99 [-Wimplicit-function-declaration]
while((line = fparseln(in, &len, &lineno, NULL, 0)) != NULL) {
^
chk_fparseln.c:15:17: warning: incompatible integer to pointer conversion assigning to 'char *' from 'int' [-Wint-conversion]
while((line = fparseln(in, &len, &lineno, NULL, 0)) != NULL) {
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
However, fparseln() is defined in util.h. I don't understand why util.h is apparently not being included at compile time. Worse yet, the code segfaults when invoked.
If I uncomment the function declaration in the code above, the code compiles cleanly and runs without errors:
$ ./chk_fparseln
1:len=16 this is line one
2:len=16 this is line two
3:len=18 this is line three
4:len=13 wow..linefour
Any ideas how to include util.h?
-Jason
最後更新:2017-10-08 00:46:07
上一篇:
Exchanging two Macs OS Sierra; different ...
下一篇:
Is it possible to instal R software at iPad Pro?
IOS 11 caused my iPads WiFi to completely stop ...
How to use Apple Pencil to mark up PDFs on iPad...
iTunes app payment history
My 7th Gen Nano is having problems with the tou...
iCloud User Not Registered for HomeKit Sharing
How to bypass iCloud account for iphone 5
connecting mbpro 11,1 to HDMI out?
IOS 11 has changed my main calendar format.
iTunes 11.4 and "*.Strings" files
File sharing
相關內容
"com.apple.installer.pagecontroller error
any idea what error 3503 is?
Underallocation Detected on Main device
The operation couldn’t be completed. (BKA...
is ctoid.exe a virus on my ipad safari browser?
iTunes Error: Declined to authorize this image ...
Keep High Efficiency Original if Available Chec...
iTunes 12.7 cannot edit playlist
High Sierra Stuck & Decryption paused
Need to unlock iphone 5 to reactivate the phone...
熱門內容
Christian Music Removed From Itunes
I'm being billed twice every month for Apple Mu...
iMac running slow
Fix disappearing album art after moving iTunes
Activation Locked iWatch
Can I change the iwatch to miles instead of kil...
I keep seeing the "You don't have permission to...
can't read any menus macbook air
iPad 2, iOs9.3, taking days to restore
charges made under itune memeberships