public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Another bit of ISO C conversion...
@ 2003-12-08  0:35 Zack Weinberg
  2003-12-08  0:39 ` Steven Bosscher
  2003-12-08  3:30 ` Kaveh R. Ghazi
  0 siblings, 2 replies; 8+ messages in thread
From: Zack Weinberg @ 2003-12-08  0:35 UTC (permalink / raw)
  To: gcc


We've had a lot of people put in time to convert GCC to ISO C style,
and I want to say that I appreciate all of that effort.  There's one
transformation that hasn't been getting done, though: use of #elif.
K&R C didn't have this directive so we have lots of nested #if
blocks.  For example, from hwint.h:

#if HOST_BITS_PER_LONG >= 64 || !defined NEED_64BIT_HOST_WIDE_INT
#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
#   define HOST_WIDE_INT long
#else
# if HOST_BITS_PER_LONGLONG >= 64
#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
#   define HOST_WIDE_INT long long
# else
#  if HOST_BITS_PER___INT64 >= 64
#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER___INT64
#   define HOST_WIDE_INT __int64
#  else
    #error "Unable to find a suitable type for HOST_WIDE_INT"
#  endif
# endif
#endif

This can become

#if HOST_BITS_PER_LONG >= 64 || !defined NEED_64BIT_HOST_WIDE_INT
#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
#   define HOST_WIDE_INT long
#elif HOST_BITS_PER_LONGLONG >= 64
#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG
#   define HOST_WIDE_INT long long
#elif HOST_BITS_PER___INT64 >= 64
#   define HOST_BITS_PER_WIDE_INT HOST_BITS_PER___INT64
#   define HOST_WIDE_INT __int64
#else
#   error "Unable to find a suitable type for HOST_WIDE_INT"
#endif

which is simpler, easier to read, and easier to modify.  

Note also that it is no longer necessary to indent the leading # of 
an #error directive; or, turnabout, it is no longer necessary to write
the leading # of any directive in column 1, so this becomes a style
decision.

zw

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Another bit of ISO C conversion...
@ 2003-12-08  1:09 Richard Kenner
  2003-12-08 14:58 ` James Lemke
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Kenner @ 2003-12-08  1:09 UTC (permalink / raw)
  To: s.bosscher; +Cc: gcc

    I would prefer to keep # in column 1 so you can still grep for
    ^#define etc.  In config/, there are quite a few files with commented
    out /* #defines */...

My preference is the indented type.  I would do a grep for "define FOO"
and would normally want to see the commented-out #defines too.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Another bit of ISO C conversion...
@ 2003-12-08 15:06 Richard Kenner
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Kenner @ 2003-12-08 15:06 UTC (permalink / raw)
  To: jim; +Cc: gcc

    > My preference is the indented type.  I would do a grep for "define FOO"
    > and would normally want to see the commented-out #defines too.

    I don't see why indentation matters here.  Either way, your grep for
    "define FOO" should still show what you describe.

Sorry I was unclear.

I was making two points:

(1) I like the indented style better since I think it's easier to read.
(2) Since I grep for "define FOO", not "#define FOO", I don't see the
ability to grep for the latter as a major advantage of not indenting.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-12-08 14:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-08  0:35 Another bit of ISO C conversion Zack Weinberg
2003-12-08  0:39 ` Steven Bosscher
2003-12-08  2:59   ` Zack Weinberg
2003-12-08  3:30 ` Kaveh R. Ghazi
2003-12-08  4:19   ` Zack Weinberg
2003-12-08  1:09 Richard Kenner
2003-12-08 14:58 ` James Lemke
2003-12-08 15:06 Richard Kenner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).