enum 초기화시 Trailing comma에 대해서
글쓴이: vani2 / 작성시간: 화, 2013/11/12 - 3:26오후
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 옵션을 주지않고 컴파일을 해보기도 하였으나, 역시 아무런 오류없이 잘 컴파일 되었습니다.
Forums:


아 실수했네요.
2번째 소스에서
struct A
{
int a,b,c;
};//이곳
이곳에서 ; 구두점이 빠졌습니다. 정정합니다.
http://www.cinsk.org/articles
http://www.cinsk.org/articles/cdiff.html#sec-2
cinsk 님의 ISO C와 ISO C++의 차이에서 말하는 C++는 C++11이 아닌 C++98입니다.
그 점을 생각하면 emum 선언의 마지막 콤마에 대해 "C++에서는 이를 허용하지 않습니다."라는 언급이 혼란스럽지 않죠?
아. C++98.. 비슷할 줄 알았는데.. 조금더
아. C++98..
비슷할 줄 알았는데..
조금더 찾아봐야겠습니다.
답변 감사합니다.
Shanemeelf
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
LewisPaify
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. موقع احتيالي عصابة من المحتالين
댓글 달기