Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.std.c > #6136 > unrolled thread
| Started by | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| First post | 2020-08-03 20:42 -0700 |
| Last post | 2020-08-05 10:47 +0100 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.std.c
7.1.4p2 vs. Annex J Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-03 20:42 -0700
Re: 7.1.4p2 vs. Annex J Ike Naar <ike@otaku.sdf.org> - 2020-08-04 05:26 +0000
Re: 7.1.4p2 vs. Annex J Philipp Klaus Krause <pkk@spth.de> - 2020-08-04 10:53 +0200
Re: 7.1.4p2 vs. Annex J Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-08-04 07:29 -0700
Re: 7.1.4p2 vs. Annex J Andy Walker <anw@cuboid.co.uk> - 2020-08-05 10:47 +0100
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2020-08-03 20:42 -0700 |
| Subject | 7.1.4p2 vs. Annex J |
| Message-ID | <87bljr84ay.fsf@nosuchdomain.example.com> |
Joe Zbiciak and I discovered this in a discussion on Quora.
N1570 7.1.4p2 says:
Provided that a library function can be declared without reference
to any type defined in a header, it is also permissible to declare
the function and use it without including its associated header.
which means that this is a valid "Hello, world" program:
int puts(const char *s);
int main(void) {
puts("Hello, world");
}
But J.2 (which is non-normative) says that the behavior is undefined if:
A function, object, type, or macro that is specified as being
declared or defined by some standard header is used before any
header that declares or defines it is included (7.1.2).
which the above program violates.
Is the intent behind that paragraph in J.2 something other than
what it seems to be? (Or am I misreading it?) Or is it just wrong?
Other than declaring a function, as permitted by 7.1.4p2, how would
a program even violate that paragraph in J.2 without also violating
a constraint?
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [next] | [standalone]
| From | Ike Naar <ike@otaku.sdf.org> |
|---|---|
| Date | 2020-08-04 05:26 +0000 |
| Message-ID | <slrn3pa8rihscr.pf3.ike@otaku.sdf.org> |
| In reply to | #6136 |
On 2020-08-04, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Joe Zbiciak and I discovered this in a discussion on Quora.
>
> N1570 7.1.4p2 says:
>
> Provided that a library function can be declared without reference
> to any type defined in a header, it is also permissible to declare
> the function and use it without including its associated header.
>
> which means that this is a valid "Hello, world" program:
>
> int puts(const char *s);
>
> int main(void) {
> puts("Hello, world");
> }
>
> But J.2 (which is non-normative) says that the behavior is undefined if:
>
> A function, object, type, or macro that is specified as being
> declared or defined by some standard header is used before any
> header that declares or defines it is included (7.1.2).
>
> which the above program violates.
The header that declares the puts() function is <stdio.h>.
The above program does not include <stdio.h>.
So the puts() function is not used before <stdio.h> is included.
[toc] | [prev] | [next] | [standalone]
| From | Philipp Klaus Krause <pkk@spth.de> |
|---|---|
| Date | 2020-08-04 10:53 +0200 |
| Message-ID | <rgb7ml$a4b$1@solani.org> |
| In reply to | #6136 |
J.2 is informative, and the part you quoted refers to normative text 7.1.2. In the current C2X draft N2479, the relevant sentenceg in 7.1.2 is: "If used, a header shall be included outside of any external declaration or definition, and it shall first be included before the first reference to any of the functions or objects it declares, or to any of the types or macros it defines." So clearly, the undefined behaviour does not happen when the header is not used at all. Philipp
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2020-08-04 07:29 -0700 |
| Message-ID | <877due8oxj.fsf@nosuchdomain.example.com> |
| In reply to | #6138 |
Philipp Klaus Krause <pkk@spth.de> writes:
> J.2 is informative, and the part you quoted refers to normative text
> 7.1.2. In the current C2X draft N2479, the relevant sentenceg in 7.1.2 is:
>
> "If used, a header shall be included outside of any external declaration
> or definition, and it shall first be included before the first reference
> to any of the functions or objects it declares, or to any of the types
> or macros it defines."
>
> So clearly, the undefined behaviour does not happen when the header is
> not used at all.
Please quote (some of) the article you're replying to.
In N2479, J.2 still says the behavior is undefined if:
- A function, object, type, or macro that is specified as being
declared or defined by some standard header is used before any
header that declares or defines it is included (7.1.2).
The normative text is clear enough in both N1570 and N2479. The text in
J.2 is at best unclear. That's the error I'm referring to.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Andy Walker <anw@cuboid.co.uk> |
|---|---|
| Date | 2020-08-05 10:47 +0100 |
| Message-ID | <rgdv6n$tal$1@gioia.aioe.org> |
| In reply to | #6136 |
On 04/08/2020 04:42, Keith Thompson wrote: > But J.2 (which is non-normative) says that the behavior is undefined if: > A function, object, type, or macro that is specified as being > declared or defined by some standard header is used before any > header that declares or defines it is included (7.1.2). This is a fine example of the ambiguity in English that makes writing standards therein fraught with difficulties. The structure is "UB if A before B". Keith reads that as forbidding "A" without "B", the same structure as "you can't go out before Saturday"; others read it as "A" being allowed by itself or following "B", but not if there is a later "B", the same structure as "you can't eat before swimming". So it's ambiguous. I used to use "while" to illustrate a similar ambiguity; the UK used to have a road sign "wait here while lights are red" in front of temporary signals for road works. But whereas most people read "while" as meaning "for as long as" [also the programming usage], in parts of the UK it means "until" ["wait here while the doctor comes"], which left locals [allegedly] waiting on the green light and driving through on red [even in Yorkshire, they're probably not that daft, though it might be an ingenious excuse following an accident]. This article is brought to you from the campaign for formal definitions of languages. [There has been a relevant thread over in "comp.lang.misc".] -- Andy Walker, Nottingham.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.std.c
csiph-web