* GCC 4.9.1 suggests -std=c99
@ 2014-09-09 14:30 Dmitry Antipov
2014-09-09 14:43 ` Eli Zaretskii
2014-09-09 14:58 ` Paul Eggert
0 siblings, 2 replies; 9+ messages in thread
From: Dmitry Antipov @ 2014-09-09 14:30 UTC (permalink / raw)
To: Paul Eggert; +Cc: Emacs development discussions
With GCC 4.9.1 and '--enable-checking --enable-check-lisp-object-type --enable-gcc-warnings':
../../trunk/src/sysdep.c: In function 'str_collate':
../../trunk/src/sysdep.c:3751:2: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for (int i = 1; i < 3; i++)
^
../../trunk/src/sysdep.c:3751:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
../../trunk/src/sysdep.c:3766:2: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for (int i = 1; i < 3; i++)
^
I.e. shouldn't we always use -std=c99 if we assume C99 anyway?
Dmitry
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 14:30 GCC 4.9.1 suggests -std=c99 Dmitry Antipov
@ 2014-09-09 14:43 ` Eli Zaretskii
2014-09-09 14:58 ` Paul Eggert
1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2014-09-09 14:43 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: eggert, emacs-devel
> Date: Tue, 09 Sep 2014 18:30:06 +0400
> From: Dmitry Antipov <dmantipov@yandex.ru>
> Cc: Emacs development discussions <emacs-devel@gnu.org>
>
> I.e. shouldn't we always use -std=c99 if we assume C99 anyway?
Not -std=c99, in any case. Perhaps -std=gnu99. We don't want strict
adherence to ANSI C99, it will flag too many false problems.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 14:30 GCC 4.9.1 suggests -std=c99 Dmitry Antipov
2014-09-09 14:43 ` Eli Zaretskii
@ 2014-09-09 14:58 ` Paul Eggert
2014-09-09 15:06 ` Eli Zaretskii
2014-09-09 15:38 ` Dmitry Antipov
1 sibling, 2 replies; 9+ messages in thread
From: Paul Eggert @ 2014-09-09 14:58 UTC (permalink / raw)
To: Dmitry Antipov; +Cc: Emacs development discussions
Dmitry Antipov wrote:
> With GCC 4.9.1 and '--enable-checking --enable-check-lisp-object-type
> --enable-gcc-warnings':
>
> ../../trunk/src/sysdep.c: In function 'str_collate':
> ../../trunk/src/sysdep.c:3751:2: error: 'for' loop initial declarations
> are only allowed in C99 or C11 mode
I don't observe this problem when I build with GCC 4.9.1. src/Makefile
says "CC = gcc -std=gnu99", so it works. Perhaps you overrode CC? Or
maybe you have an old version of autoconf?
While we're on the topic, --enable-gcc-warnings generates false alarms
when combined with arbitrary other options like
--enable-check-lisp-object-type, CFLAGS='-g3 -O0', etc. I do not take
the trouble to pacify GCC for all combinations of build options, just
for the default ones.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 14:58 ` Paul Eggert
@ 2014-09-09 15:06 ` Eli Zaretskii
2014-09-09 15:21 ` Paul Eggert
2014-09-09 15:38 ` Dmitry Antipov
1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2014-09-09 15:06 UTC (permalink / raw)
To: Paul Eggert; +Cc: dmantipov, emacs-devel
> Date: Tue, 09 Sep 2014 07:58:54 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> Cc: Emacs development discussions <emacs-devel@gnu.org>
>
> Dmitry Antipov wrote:
> > With GCC 4.9.1 and '--enable-checking --enable-check-lisp-object-type
> > --enable-gcc-warnings':
> >
> > ../../trunk/src/sysdep.c: In function 'str_collate':
> > ../../trunk/src/sysdep.c:3751:2: error: 'for' loop initial declarations
> > are only allowed in C99 or C11 mode
>
> I don't observe this problem when I build with GCC 4.9.1.
But do we actually want to use such initializations inside a for loop?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 15:06 ` Eli Zaretskii
@ 2014-09-09 15:21 ` Paul Eggert
2014-09-09 15:50 ` Eli Zaretskii
0 siblings, 1 reply; 9+ messages in thread
From: Paul Eggert @ 2014-09-09 15:21 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: dmantipov, emacs-devel
Eli Zaretskii wrote:
> do we actually want to use such initializations inside a for loop?
It's a better style, as it scopes the control variable better. And we
are assuming C99 in the trunk nowadays.
It will be a portability problem only if we run into a pre-C99 compiler
that supports C99-style statements-before-declarations (which we're
already using in the trunk) but does not support a C99-style declaration
as the first clause of a for-loop. I'd be a bit surprised if such a
compiler were in current use (but then I've been surprised before ...).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 15:21 ` Paul Eggert
@ 2014-09-09 15:50 ` Eli Zaretskii
2014-09-09 16:42 ` Dmitry Antipov
2014-09-09 17:11 ` Paul Eggert
0 siblings, 2 replies; 9+ messages in thread
From: Eli Zaretskii @ 2014-09-09 15:50 UTC (permalink / raw)
To: Paul Eggert; +Cc: dmantipov, emacs-devel
> Date: Tue, 09 Sep 2014 08:21:54 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: dmantipov@yandex.ru, emacs-devel@gnu.org
>
> Eli Zaretskii wrote:
> > do we actually want to use such initializations inside a for loop?
>
> It's a better style, as it scopes the control variable better. And we
> are assuming C99 in the trunk nowadays.
>
> It will be a portability problem only if we run into a pre-C99 compiler
> that supports C99-style statements-before-declarations (which we're
> already using in the trunk) but does not support a C99-style declaration
> as the first clause of a for-loop. I'd be a bit surprised if such a
> compiler were in current use (but then I've been surprised before ...).
I think we should have discussed whether to use these C99 features
before actually starting using them. Emacs definitely has certain
coding style, which doesn't include these.
I understand the rationale for using C99 features for which there's no
reasonably practical alternatives, or rely on C99 semantics where
earlier versions left things undefined. But the above don't belong to
either class.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 15:50 ` Eli Zaretskii
@ 2014-09-09 16:42 ` Dmitry Antipov
2014-09-09 17:11 ` Paul Eggert
1 sibling, 0 replies; 9+ messages in thread
From: Dmitry Antipov @ 2014-09-09 16:42 UTC (permalink / raw)
To: Eli Zaretskii, Paul Eggert; +Cc: emacs-devel
On 09/09/2014 07:50 PM, Eli Zaretskii wrote:
>> It's a better style
IMHO only if it is just a control variable, and in the only loop.
If it isn't, e.g. in:
int i;
...
for (i = 0; i < XXX; i++)
...
i = a;
a = b;
b = i;
...
for (i = 0; i < YYY; i++)
...
then C99/C++-style:
...
for (int i = 0; i < XXX; i++)
...
int i = a;
a = b;
b = i;
...
for (int i = 0; i < YYY; i++)
...
becomes a monkey's typing exercise.
Dmitry
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 15:50 ` Eli Zaretskii
2014-09-09 16:42 ` Dmitry Antipov
@ 2014-09-09 17:11 ` Paul Eggert
1 sibling, 0 replies; 9+ messages in thread
From: Paul Eggert @ 2014-09-09 17:11 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: dmantipov, emacs-devel
Eli Zaretskii wrote:
> we should have discussed whether to use these C99 features
> before actually starting using them.
We discussed them in Bug#17487. As I mentioned, Emacs developers
routinely made changes that used these features, I was occasionally
auditing the code and removing their use for no practical reason (only
because of standards-conformance issues), and I got tired of this
pointless task.
My guess is that when Michael Albinus introduced the 'for (int i = 1;
...' loop in trunk bzr 117771, he wasn't consciously thinking "Oh boy! I
get to use C99 now! I will now change Emacs's style!" Most likely he
was just using a common and natural idiom that worked for him, and
didn't notice that it wouldn't port to C89 and was therefore contrary to
Emacs's old style rules.
> Emacs definitely has certain
> coding style, which doesn't include these.
The part of Emacs's style that disallowed these C99 features was there
primarily because of C89's restrictions. It's often not the best style
and we should not insist on it.
I agree with Dmitry that we should not insist on a declaration as the
first clause of every for loop, but there doesn't seem to be a good
reason to prohibit a declaration there, whereas there is a good reason
(more-accurate scoping) to allow it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: GCC 4.9.1 suggests -std=c99
2014-09-09 14:58 ` Paul Eggert
2014-09-09 15:06 ` Eli Zaretskii
@ 2014-09-09 15:38 ` Dmitry Antipov
1 sibling, 0 replies; 9+ messages in thread
From: Dmitry Antipov @ 2014-09-09 15:38 UTC (permalink / raw)
To: Paul Eggert; +Cc: Emacs development discussions
On 09/09/2014 06:58 PM, Paul Eggert wrote:
> I don't observe this problem when I build with GCC 4.9.1. src/Makefile says
> "CC = gcc -std=gnu99", so it works. Perhaps you overrode CC?
Argh, yes, it was an explicit CC=... in make.
Dmitry
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-09-09 17:11 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-09 14:30 GCC 4.9.1 suggests -std=c99 Dmitry Antipov
2014-09-09 14:43 ` Eli Zaretskii
2014-09-09 14:58 ` Paul Eggert
2014-09-09 15:06 ` Eli Zaretskii
2014-09-09 15:21 ` Paul Eggert
2014-09-09 15:50 ` Eli Zaretskii
2014-09-09 16:42 ` Dmitry Antipov
2014-09-09 17:11 ` Paul Eggert
2014-09-09 15:38 ` Dmitry Antipov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.