c99에서 추가된 가변 배열 멤버에 값을 할당하는 방법에 대해 소개합니다.

#include <stdio.h>

typedef struct _line {
	int size;
	int data[];
}line;

void funfun(line * abc){
	if(abc->data[0] == 1 ){
		printf("You can't touch this");

	}
	else{
		printf("MC Hammer");
	}

}

위와 같은 코드에서 참인 경우의 if 분기가 실행되도록 테스트를 설계하려면, 일반적인 테스트 데이터 입력 방법로는 값을 넣을 수 없습니다.
가변 배열 멤버(Flexible array member)이기 때문입니다.

따라서, 테스트 정보 탭의 호출 전 코드를 이용하여 아래와 같이 값을 넣어야 합니다.

size_t this_length = 5;
abc = (line *)malloc (sizeof (line) + this_length);
abc->data[0] = 1;

Need more help with this?
Don’t hesitate to contact us here.

Thanks for your feedback.