Re: [patch] C99 & /usr/share/misc/style

Joseph Koshy <[email protected]>
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <[email protected]>
j.k> +/*
j.k> + * Enum constants are capitalized.  Commas are recommended for the last
j.k> + * element as using them can minimize diffs.
j.k> + */
j.k>  enum enumtype {
j.k>  	ONE,
j.k> -	TWO
j.k> +	TWO,
j.k>  };

v.u> This is in general my preference too, but spare a thought for C++
v.u> where that comma is a -Wpedantic warning.  Probably need to say
v.u> something about not using that in a header file that can be included
v.u> by C++ programs.

That's a good point; I will add a note.

This would be an issue for C+-03 and earlier language versions
(which I believe are based off the C89 C standard).  C++-11 and
later versions of C++ are I believe based off C99; these C++
versions should support the trailing comma syntax for enumeration
values.

  % echo "enum Z { A, B, };" > a.cc

  % c++ -c -pedantic -std=c++03 a.cc 
  a.cc:1:16: warning: comma at end of enumerator list [-Wpedantic]
   enum Z { A, B, };
                ^

  % c++ -c -pedantic -std=c++11 a.cc
  % 

Is compatibility with the C++ language a formal goal for
NetBSD's C code?  If so, we should perhaps specify somewhere
the C++ version (c++-{03,11,17,..}) that we should be compatible
with.

Thanks,
Joseph Koshy
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.