Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

As of next Thursday, UNIX will be flushed in favor of TOPS-10. Please update your programs.


devel / comp.lang.c / Re: Clang vs GCC on block scope declaration of inline function

SubjectAuthor
* Clang vs GCC on block scope declaration of inline functionarnab chatterjee
+* Re: Clang vs GCC on block scope declaration of inline functionTim Rentsch
|`- Re: Clang vs GCC on block scope declaration of inline functionarnab chatterjee
`* Re: Clang vs GCC on block scope declaration of inline functionKaz Kylheku
 `- Re: Clang vs GCC on block scope declaration of inline functionarnab chatterjee

1
Clang vs GCC on block scope declaration of inline function

<0beab85a-6ce0-4f29-b6c8-9346581b11c0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28295&group=comp.lang.c#28295

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1baa:b0:403:996b:3ae with SMTP id bp42-20020a05622a1baa00b00403996b03aemr712303qtb.9.1693211431405;
Mon, 28 Aug 2023 01:30:31 -0700 (PDT)
X-Received: by 2002:ad4:551d:0:b0:63c:fe6e:bb4 with SMTP id
pz29-20020ad4551d000000b0063cfe6e0bb4mr790039qvb.0.1693211431128; Mon, 28 Aug
2023 01:30:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 28 Aug 2023 01:30:30 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=157.40.105.182; posting-account=xxYVqQoAAAA0dTZJaXjtAqb6GD4t-dYb
NNTP-Posting-Host: 157.40.105.182
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0beab85a-6ce0-4f29-b6c8-9346581b11c0n@googlegroups.com>
Subject: Clang vs GCC on block scope declaration of inline function
From: arnabcha...@gmail.com (arnab chatterjee)
Injection-Date: Mon, 28 Aug 2023 08:30:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1966
 by: arnab chatterjee - Mon, 28 Aug 2023 08:30 UTC

Hello all,

I'd like to confirm if there's a bug in GCC's compilation of the following code:

int main(void) { void f(void); f(); }
inline void f(void) {}

gcc successfully generates an executable, but clang gives the following error:
" undefined reference to `f' ".

It seems to me that a linker error is expected here, because (all) file scope
declarations of `f' specify inline without extern,so its given definition should
be an inline definition, not an external one (also not prohibiting the latter).

Consequently, adding a (non-inline) external definition of `f' in another file
makes the linker complain about "multiple definition of `f'" when the first file
is compiled with gcc, but an executable is generated when compiled with clang.

Also, explicitly specifying inline in the block scope declaration makes gcc's
outcome consistent with that of clang (ld reports "undefined reference to `f'").

Regards,
cHaR.

Re: Clang vs GCC on block scope declaration of inline function

<86msybxot4.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28311&group=comp.lang.c#28311

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Clang vs GCC on block scope declaration of inline function
Date: Mon, 28 Aug 2023 06:46:15 -0700
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <86msybxot4.fsf@linuxsc.com>
References: <0beab85a-6ce0-4f29-b6c8-9346581b11c0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="61b7a310fb4086afc4b0d02730d52894";
logging-data="1819250"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EOX70M8Q3J6BYY8BZzatQ2QAYCBkjoi4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:XfL1vwjlB7R/gEWURtBdhd5BIzU=
sha1:OqTca6x8ExjOdh/Cnq0TaY8Va6A=
 by: Tim Rentsch - Mon, 28 Aug 2023 13:46 UTC

arnab chatterjee <arnabchatterjeeofficial@gmail.com> writes:

> Hello all,
>
> I'd like to confirm if there's a bug in GCC's compilation of the
> following code:
>
> int main(void) { void f(void); f(); }
> inline void f(void) {}
>
> gcc successfully generates an executable, but clang gives the
> following error: " undefined reference to `f' ".

My reading of the C standard is that what gcc does and what clang
does are both allowed by the standard. The declarations of f()
give it external linkage. There is a use of f(). Because of the
use, there must be an external definition of f(), but there isn't
one. Because there isn't, the program has undefined behavior.
Hence either working or giving a link error is allowed.

> It seems to me that a linker error is expected here, because (all)
> file scope declarations of `f' specify inline without extern,so its
> given definition should be an inline definition, not an external one
> (also not prohibiting the latter).

It might be reasonable to expect a link error, but it is not
required, by virtue of the situation being undefined behavior.

> Consequently, adding a (non-inline) external definition of `f' in
> another file makes the linker complain about "multiple definition of
> `f'" when the first file is compiled with gcc, but an executable is
> generated when compiled with clang.

My reading of this result is that what gcc does does not conform
to what the C standard says. AFAICT the program is conforming
and has no undefined behavior, so it should work. In this case
clang is right, and gcc is wrong.

> Also, explicitly specifying inline in the block scope declaration
> makes gcc's outcome consistent with that of clang (ld reports
> "undefined reference to `f'").

That should make no difference. The one-file case is still
undefined behavior, the two-file case is still well-defined
behavior.

Re: Clang vs GCC on block scope declaration of inline function

<20230828090056.67@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28321&group=comp.lang.c#28321

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Clang vs GCC on block scope declaration of inline function
Date: Mon, 28 Aug 2023 16:20:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20230828090056.67@kylheku.com>
References: <0beab85a-6ce0-4f29-b6c8-9346581b11c0n@googlegroups.com>
Injection-Date: Mon, 28 Aug 2023 16:20:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="10c6d898fd3a93281822b96d674293f3";
logging-data="1873391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9VuXFRwjQaN9I3E2pilhWmrAKhAav7V4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:uFCzNGpN0EYhFj2UexvbueS4Vso=
 by: Kaz Kylheku - Mon, 28 Aug 2023 16:20 UTC

On 2023-08-28, arnab chatterjee <arnabchatterjeeofficial@gmail.com> wrote:
> Hello all,
>
> I'd like to confirm if there's a bug in GCC's compilation of the following code:
>
> int main(void) { void f(void); f(); }
> inline void f(void) {}

How are you invoking GCC?

If you've not specified a dialect to GCC, you're working in GNU C.

GNU C had inline functions long before C99 standardized them, and
of course they are not exactly the same as ISO C inline functions.

Just sayin'.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Clang vs GCC on block scope declaration of inline function

<91c53906-f8a6-4e33-ba04-5bd13f06cf5an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28386&group=comp.lang.c#28386

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:551c:0:b0:649:f255:e483 with SMTP id pz28-20020ad4551c000000b00649f255e483mr744847qvb.5.1693283414342;
Mon, 28 Aug 2023 21:30:14 -0700 (PDT)
X-Received: by 2002:a05:6a00:98d:b0:68b:db4f:73be with SMTP id
u13-20020a056a00098d00b0068bdb4f73bemr5517837pfg.6.1693283413768; Mon, 28 Aug
2023 21:30:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 28 Aug 2023 21:30:13 -0700 (PDT)
In-Reply-To: <86msybxot4.fsf@linuxsc.com>
Injection-Info: google-groups.googlegroups.com; posting-host=157.40.113.246; posting-account=xxYVqQoAAAA0dTZJaXjtAqb6GD4t-dYb
NNTP-Posting-Host: 157.40.113.246
References: <0beab85a-6ce0-4f29-b6c8-9346581b11c0n@googlegroups.com> <86msybxot4.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <91c53906-f8a6-4e33-ba04-5bd13f06cf5an@googlegroups.com>
Subject: Re: Clang vs GCC on block scope declaration of inline function
From: arnabcha...@gmail.com (arnab chatterjee)
Injection-Date: Tue, 29 Aug 2023 04:30:14 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3687
 by: arnab chatterjee - Tue, 29 Aug 2023 04:30 UTC

On Monday, August 28, 2023 at 7:16:32 PM UTC+5:30, Tim Rentsch wrote:
> arnab chatterjee <arnabchatte...@gmail.com> writes:
>
> > Hello all,
> >
> > I'd like to confirm if there's a bug in GCC's compilation of the
> > following code:
> >
> > int main(void) { void f(void); f(); }
> > inline void f(void) {}
> >
> > gcc successfully generates an executable, but clang gives the
> > following error: " undefined reference to `f' ".
> My reading of the C standard is that what gcc does and what clang
> does are both allowed by the standard. The declarations of f()
> give it external linkage. There is a use of f(). Because of the
> use, there must be an external definition of f(), but there isn't
> one. Because there isn't, the program has undefined behavior.
> Hence either working or giving a link error is allowed.
> > It seems to me that a linker error is expected here, because (all)
> > file scope declarations of `f' specify inline without extern,so its
> > given definition should be an inline definition, not an external one
> > (also not prohibiting the latter).
> It might be reasonable to expect a link error, but it is not
> required, by virtue of the situation being undefined behavior.
> > Consequently, adding a (non-inline) external definition of `f' in
> > another file makes the linker complain about "multiple definition of
> > `f'" when the first file is compiled with gcc, but an executable is
> > generated when compiled with clang.
> My reading of this result is that what gcc does does not conform
> to what the C standard says. AFAICT the program is conforming
> and has no undefined behavior, so it should work. In this case
> clang is right, and gcc is wrong.
> > Also, explicitly specifying inline in the block scope declaration
> > makes gcc's outcome consistent with that of clang (ld reports
> > "undefined reference to `f'").
> That should make no difference. The one-file case is still
> undefined behavior, the two-file case is still well-defined
> behavior.

I see; I had not considered the possibility that absence of external definition
in the first case (even though one is required) would cause undefined behavior.

Thank you for clarifying the difference between the single file and multi file
examples;I think I'll submit a bug report describing only the two-file scenario.

Re: Clang vs GCC on block scope declaration of inline function

<4026d5b5-24b4-493f-8a9e-e8fbce28a792n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=28387&group=comp.lang.c#28387

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:4009:b0:40f:91be:b62a with SMTP id cf9-20020a05622a400900b0040f91beb62amr80160qtb.6.1693283438548; Mon, 28 Aug 2023 21:30:38 -0700 (PDT)
X-Received: by 2002:a63:3648:0:b0:56b:dc28:69a8 with SMTP id d69-20020a633648000000b0056bdc2869a8mr4440555pga.0.1693283437859; Mon, 28 Aug 2023 21:30:37 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!69.80.99.14.MISMATCH!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 28 Aug 2023 21:30:37 -0700 (PDT)
In-Reply-To: <20230828090056.67@kylheku.com>
Injection-Info: google-groups.googlegroups.com; posting-host=157.40.113.246; posting-account=xxYVqQoAAAA0dTZJaXjtAqb6GD4t-dYb
NNTP-Posting-Host: 157.40.113.246
References: <0beab85a-6ce0-4f29-b6c8-9346581b11c0n@googlegroups.com> <20230828090056.67@kylheku.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4026d5b5-24b4-493f-8a9e-e8fbce28a792n@googlegroups.com>
Subject: Re: Clang vs GCC on block scope declaration of inline function
From: arnabcha...@gmail.com (arnab chatterjee)
Injection-Date: Tue, 29 Aug 2023 04:30:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 28
 by: arnab chatterjee - Tue, 29 Aug 2023 04:30 UTC

On Monday, August 28, 2023 at 9:51:03 PM UTC+5:30, Kaz Kylheku wrote:
> On 2023-08-28, arnab chatterjee <arnabchatte...@gmail.com> wrote:
> > Hello all,
> >
> > I'd like to confirm if there's a bug in GCC's compilation of the following code:
> >
> > int main(void) { void f(void); f(); }
> > inline void f(void) {}
> How are you invoking GCC?
>
> If you've not specified a dialect to GCC, you're working in GNU C.
>
> GNU C had inline functions long before C99 standardized them, and
> of course they are not exactly the same as ISO C inline functions.
>
> Just sayin'.
>
> --
> TXR Programming Language: http://nongnu.org/txr
> Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
> Mastodon: @Kazi...@mstdn.ca

I used gcc 13.0.1 as: gcc-13 -std=c17 -Wall -Wextra -pedantic
Also tried with -std=c99 and -std=c2x dialects along with -O2 and -O3 enabled
(hoping higher optimization might trigger some warning), but outcome was same.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor