閱讀333 返回首頁    go iPhone_iPad_Mac_apple


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

  上一篇:go Exchanging two Macs  OS Sierra; different ...
  下一篇:go Is it possible to instal R software at iPad Pro?