Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

C99표준에추가된C언어의엄청좋은기능

From ZeroWiki

두가지. 선언을 블록의 앞이 아니라 중간에도 선언 가능. 배열을 동적으로 저렇게 할당하다니 -_-... 함수내에서 함수 선언 가능.

#include <stdio.h>

int main()
{
int n;
printf("Array Size? ");
scanf("%d", &n);
int x[n];

int i;
for (i = 0; i < n; i++) {
x[i] = i * 10;
printf("%d ", x[i]);
}

printf("\n");
return 0;
}

AnswerMe)

  • 흠 이상하네 ㅡ.ㅡ;; gcc에서는 되고, VS.net에서는 에러를;; 잘못 컴파일 한건가? 혹시 VS.net에서는 안되나요? - [eternalbleu]
  • 흐음... C에서 동적할당을 하기 위해서는 new나 malloc 정도의 키워드를 사용해야 하지 않나요?? 혹시.. 컴파일 옵션을 달리해야 하는??;; - 이승한
  • 알아본 결과 C99에서 지원되는 것으로 표준이 맞으며, 단지 VS의 컴파일러가 C99를 완전히 만족시키지 않기 때문이라고함. gcc도 3.0 이후버전부터 지원된 기능으로 variable-length array 이라고 부르는군요. (gcc는 C99발표이전부터 extension 의 형태로 지원을 하기는 했다고 합니다.) - [eternalbleu]
Open source development using C99
The new variable-length array (VLA) feature is partially available. Simple VLAs will work. However, this is a pure coincidence; in fact, GNU C has its own variable-length array support. As a result, while simple code using variable-length arrays will work, a lot of code will run into the differences between the older GNU C support for VLAs and the C99 definition. Declare arrays whose length is a local variable, but don't try to go much further.