Why doesn't cc -ansi disable conflicting type for getline from stdio.h?

Edward Sanford Sutton, III mirror176 at hotmail.com
Mon Jun 14 21:10:34 UTC 2021


  Trying to work on properly learning C so following K&R second edition
of C Programming Language. Found in manpage that -std=c89 or -ansi can
be passed to setup a more compatible set of build rules which hid
warnings about how main is defined.
  My understanding is that this should also cause getline to not be
defined in /usr/include/stdio.h. Is there a reason that "#if
__POSIX_VISIBLE >= 200809" should trigger as true in there with
-std=c89? Section 1.9 page 29 uses that function name in its own sample
code. I know I could rename it, but is there a way to disable this book
to modern compiler incompatibility from command line as I was
attempting? I've tried to call the compiler executable directly and also
attempted with /usr/local/bin/clang10 without different results. I tried
to disable ccache from environment variable setting but don't know how
to tell if that took effect properly nor would I expect it should be
relevant.
  If you have a different starting suggestion for learning C then I'd be
interested but it seemed to be the guidance I found with internet
searching and other starter books I own usually mix c and c++ with more
of a c++ and nonunix focus. Also trying to work on learning vi while
doing this; hard to wrap my brain around insert (sometimes?) backing me
up 1 character when exiting the mode.
  If helpful I can include the code I typed form the page of text, or a
smaller example showing the problem. Below is compiler command with
output and /usr/lib/clang/11.0.1/include does not have a copy of stdio.h
that I see.

 /usr/bin/clang -ansi -v characterarrays.c
FreeBSD clang version 11.0.1 (git at github.com:llvm/llvm-project.git
llvmorg-11.0.1-0-g43ff75f2c3fe)
Target: x86_64-unknown-freebsd13.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang" -cc1 -triple x86_64-unknown-freebsd13.0 -emit-obj
-mrelax-all -disable-free -disable-llvm-verifier -discard-value-names
-main-file-name characterarrays.c -mrelocation-model static
-mframe-pointer=all -fno-rounding-math -mconstructor-aliases
-munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining
-debugger-tuning=gdb -v -resource-dir /usr/lib/clang/11.0.1 -std=c89
-fdebug-compilation-dir /home/mirror176/programming/k&r -ferror-limit 19
-fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o
/tmp/characterarrays-a7e144.o -x c characterarrays.c
clang -cc1 version 11.0.1 based upon LLVM 11.0.1 default target
x86_64-unknown-freebsd13.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/clang/11.0.1/include
 /usr/include
End of search list.
characterarrays.c:4:5: error: conflicting types for 'getline'
int getline(char line[], int maxline);
    ^
/usr/include/stdio.h:380:10: note: previous declaration is here
ssize_t  getline(char ** __restrict, size_t * __restrict, FILE *
__restrict);
         ^
characterarrays.c:16:37: error: too few arguments to function call,
expected 3, have 2
        while ((len = getline(line, MAXLINE)) > 0)
                      ~~~~~~~              ^
/usr/include/stdio.h:380:10: note: 'getline' declared here
ssize_t  getline(char ** __restrict, size_t * __restrict, FILE *
__restrict);
         ^
characterarrays.c:27:5: error: conflicting types for 'getline'
int getline(char a[], int lim)
    ^
/usr/include/stdio.h:380:10: note: previous declaration is here
ssize_t  getline(char ** __restrict, size_t * __restrict, FILE *
__restrict);
         ^
characterarrays.c:31:45: error: use of undeclared identifier 'c1'
        for (i=0; i<lim-1 && (c=getchar())!=EOF && c1='\n'; ++i)
                                                   ^
characterarrays.c:32:3: error: use of undeclared identifier 's'
                s[i]=c;
                ^
characterarrays.c:33:11: warning: multi-character character constant
[-Wmultichar]
        if (c == '/n') {
                 ^
characterarrays.c:34:3: error: use of undeclared identifier 's'
                s[i] = c;
                ^
characterarrays.c:37:2: error: use of undeclared identifier 's'
        s[i] = '\0';
        ^
1 warning and 7 errors generated.

Thanks,
Edward Sutton, III

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20210614/37637c15/attachment.sig>


More information about the freebsd-questions mailing list