enum 초기화시 Trailing comma에 대해서

vani2의 이미지

http://stackoverflow.com/questions/6372650/trailing-commas-and-c

위 문서에 따르면 C99와 C++11에선 enum 나열식 뒤에 ','를 붙일 수 있다고 설명하고 있습니다.

#include <iostream>
 
using namespace std;
 
enum Alpha{A, B, C,};
 
int main()
{
  Alpha a = Alpha::A;
 
  cout << a <<endl;
 
  return 0
}

그래서 위 코드를 VS2013과 G++에서 컴파일 해보았습니다.

두 컴파일러 모두 아무 문제없이 컴파일 되었습니다.

그런데 문제는..

http://www.cinsk.org/articles/cdiff.html#sec-5-15

이 문서에 따르면 C++에선 Trailing comma를 지원하지 않는다고 합니다.

조금 혼란스럽네요.

-----------------------------------------------------------------------------------

Q1. Trailing comma이 표준이라고 할 수 있을까요?

Q2. 그리고 저는 POD타입, 배열등을 초기화할때 초기식 맨 뒤에 ','를 붙여 확장성을 높이고 있는데요.

#include <iostream>
 
using namespace std;
 
struct A
{
 int a,b,c;
}
 
int main()
{
  A a = {1,2,3,}; //여기
 
  cout << a.a <<endl;
 
  return 0
}

혹여나 이런 코딩 스타일은 좋지않나요?

ps. 혹시 몰라서 G++에서 std=c++11 옵션을 주지않고 컴파일을 해보기도 하였으나, 역시 아무런 오류없이 잘 컴파일 되었습니다.

vani2의 이미지

2번째 소스에서

struct A
{
int a,b,c;
};//이곳

이곳에서 ; 구두점이 빠졌습니다. 정정합니다.

chanik의 이미지

http://www.cinsk.org/articles/cdiff.html#sec-2

Quote:
이 글은 C99와 C++98의 차이를 다룹니다

cinsk 님의 ISO C와 ISO C++의 차이에서 말하는 C++는 C++11이 아닌 C++98입니다.
그 점을 생각하면 emum 선언의 마지막 콤마에 대해 "C++에서는 이를 허용하지 않습니다."라는 언급이 혼란스럽지 않죠?
vani2의 이미지

아. C++98..

비슷할 줄 알았는데..

조금더 찾아봐야겠습니다.

답변 감사합니다.

EarnestDraic의 이미지

May I just say what a relief to uncover a person that genuinely understands what theyre talking about online. You definitely know how to bring an issue to light and make it important. More people have to look at this and understand this side of the story. Its surprising youre not more popular because you certainly possess the gift. free spins no deposit

Stephennof의 이미지

Hello I am so thrilled I found your blog I really found you by mistake while I was browsing on Digg for something else Regardless I am here now and would just like to say many thanks for a remarkable post and a all round enjoyable blog I also love the theme/design I don’t have time to browse it all at the minute but I have bookmarked it and also added your RSS feeds so when I have time I will be back to read a great deal more Please do keep up the fantastic b. موقع احتيالي عصابة من المحتالين

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.