[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CC Mode and electric-pair "problem".
From: |
Yuri Khan |
Subject: |
Re: CC Mode and electric-pair "problem". |
Date: |
Tue, 19 Jun 2018 01:07:36 +0700 |
On Tue, Jun 19, 2018 at 12:25 AM João Távora <address@hidden> wrote:
> Alan Mackenzie <address@hidden> writes:
> > Why? They are now C statements, and would be handled by the compiler as
> > such.
>
> Clarify "would". Because this doesn't compile. My compiler doesn't even
> seem to look at anything after the unterminated string:
>
> int main () {
> printf("foo
> );
> printf("bar");
> return 0;
> }
Mine does. After finding a syntax error, a typical C compiler
continues scanning the source, attempting to diagnose more errors.
See:
```
int main() {
printf("foo
);
return baz;
}
$ gcc test1.c
test1.c: In function ‘main’:
test1.c:2:5: warning: implicit declaration of function ‘printf’
[-Wimplicit-function-declaration]
printf("foo
^
test1.c:2:5: warning: incompatible implicit declaration of built-in
function ‘printf’
test1.c:2:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
test1.c:2:12: warning: missing terminating " character
printf("foo
^
test1.c:2:5: error: missing terminating " character
printf("foo
^
test1.c:2:5: error: too few arguments to function ‘printf’
test1.c:4:12: error: ‘baz’ undeclared (first use in this function)
return baz;
^
test1.c:4:12: note: each undeclared identifier is reported only once
for each function it appears in
```
Observe that the compiler first complains about the unclosed string
literal, then too few arguments, and then undeclared identifier ‘baz’.
If the compiler thought the string terminal continued, it would skip
everything until the end of file silently.
Now add a few characters:
```
int main() {
printf("foo
"bar");
return baz;
}
$ gcc test2.c
test2.c: In function ‘main’:
test2.c:2:5: warning: implicit declaration of function ‘printf’
[-Wimplicit-function-declaration]
printf("foo
^
test2.c:2:5: warning: incompatible implicit declaration of built-in
function ‘printf’
test2.c:2:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
test2.c:2:12: warning: missing terminating " character
printf("foo
^
test2.c:2:5: error: missing terminating " character
printf("foo
^
test2.c:4:12: error: ‘baz’ undeclared (first use in this function)
return baz;
^
test2.c:4:12: note: each undeclared identifier is reported only once
for each function it appears in
```
Observe the compiler no longer complains about too few arguments to
‘printf’. This is consistent with the hypothesis that it discarded the
unterminated literal at the newline, and took "bar" as the required
format string argument.
- Re: CC Mode and electric-pair "problem"., (continued)
- Re: CC Mode and electric-pair "problem"., Eli Zaretskii, 2018/06/18
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/18
- Re: CC Mode and electric-pair "problem"., Eli Zaretskii, 2018/06/18
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/19
- Re: CC Mode and electric-pair "problem"., Eli Zaretskii, 2018/06/19
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/19
- Re: CC Mode and electric-pair "problem"., Glenn Morris, 2018/06/18
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/18
- Re: CC Mode and electric-pair "problem"., Alan Mackenzie, 2018/06/18
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/18
- Re: CC Mode and electric-pair "problem".,
Yuri Khan <=
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/18
- Re: CC Mode and electric-pair "problem"., Alan Mackenzie, 2018/06/18
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/18
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/06/18
- Re: CC Mode and electric-pair "problem"., Stefan Monnier, 2018/06/18
- Re: CC Mode and electric-pair "problem"., Clément Pit-Claudel, 2018/06/18
- Re: CC Mode and electric-pair "problem"., Stefan Monnier, 2018/06/19
- Re: CC Mode and electric-pair "problem"., Clément Pit-Claudel, 2018/06/20
- Fontifying unterminated strings [was: CC Mode and electric-pair "problem".], Alan Mackenzie, 2018/06/26
- Re: Fontifying unterminated strings [was: CC Mode and electric-pair "problem".], João Távora, 2018/06/26