Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jun 2021 14:10:28 -0700
From:      "Edward Sanford Sutton, III" <mirror176@hotmail.com>
To:        freebsd-questions@freebsd.org
Subject:   Why doesn't cc -ansi disable conflicting type for getline from stdio.h?
Message-ID:  <DM6PR03MB3674F7BEABFB85367768AE1BE6319@DM6PR03MB3674.namprd03.prod.outlook.com>

next in thread | raw e-mail | index | archive | help
--LGwTt1xj1LKnYCBVxoiegy1f8qZiYRC1p
Content-Type: multipart/mixed; boundary="y92VoQwPpesYOhlfQQd8DmThc5KmxdnyL";
 protected-headers="v1"
From: "Edward Sanford Sutton, III" <mirror176@hotmail.com>
To: freebsd-questions@freebsd.org
Message-ID: <9d793a27-659e-7b0a-ad9e-6eee34c2dc62@hotmail.com>
Subject: Why doesn't cc -ansi disable conflicting type for getline from
 stdio.h?

--y92VoQwPpesYOhlfQQd8DmThc5KmxdnyL
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable

  Trying to work on properly learning C so following K&R second edition
of C Programming Language. Found in manpage that -std=3Dc89 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 >=3D 200809" should trigger as true in there with
-std=3Dc89? 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@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=3Dall -fno-rounding-math -mconstructor-aliases
-munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining
-debugger-tuning=3Dgdb -v -resource-dir /usr/lib/clang/11.0.1 -std=3Dc89
-fdebug-compilation-dir /home/mirror176/programming/k&r -ferror-limit 19
-fgnuc-version=3D4.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 =3D 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=3D0; i<lim-1 && (c=3Dgetchar())!=3DEOF && c1=3D'\n'; ++i)
                                                   ^
characterarrays.c:32:3: error: use of undeclared identifier 's'
                s[i]=3Dc;
                ^
characterarrays.c:33:11: warning: multi-character character constant
[-Wmultichar]
        if (c =3D=3D '/n') {
                 ^
characterarrays.c:34:3: error: use of undeclared identifier 's'
                s[i] =3D c;
                ^
characterarrays.c:37:2: error: use of undeclared identifier 's'
        s[i] =3D '\0';
        ^
1 warning and 7 errors generated.

Thanks,
Edward Sutton, III


--y92VoQwPpesYOhlfQQd8DmThc5KmxdnyL--

--LGwTt1xj1LKnYCBVxoiegy1f8qZiYRC1p
Content-Type: application/pgp-signature; name="OpenPGP_signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="OpenPGP_signature"

-----BEGIN PGP SIGNATURE-----

wnsEABYIACMWIQRcG7F5PMnFLs9QmH7pNfr2Xm5OKAUCYMfFxAUDAAAAAAAKCRDpNfr2Xm5OKH58
AP4rqXdp6w/rV+8VLL8hozYqeUfp45NTc1XMXeSgZvrXJwEAmEupshm8yyAkY65Tnp4UMQgXCDYg
uLKAiTxALUjT4wg=
=FeKl
-----END PGP SIGNATURE-----

--LGwTt1xj1LKnYCBVxoiegy1f8qZiYRC1p--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DM6PR03MB3674F7BEABFB85367768AE1BE6319>