구조체를 선언 한 다음 해당 구조체의 배열을 선언 한 다음 해당 구조체 배열의 배열을 선언하려고합니다. 첫 번째 두 부분은 괜찮습니다. 세 번째 부분과 고민하고 있습니다.구조체의 배열 배열 채우기?
배열을 not_trace_groups에 할당하려고하면 내 코드가 컴파일되지 않고 올바르게 수행하는 방법을 알 수 없습니다.
typedef struct trace
{
uint32_t upstream_pin;
uint32_t dnstream_pin;
uint32_t led_pin;
}trace;
trace all_traces[NUM_TRACES] = {{GPIO_Pin_3, GPIO_Pin_7, GPIO_Pin_0},
{GPIO_Pin_4, GPIO_Pin_6 , GPIO_Pin_1},
{GPIO_Pin_5, GPIO_Pin_5 , PIO_Pin_1},
{GPIO_Pin_6, GPIO_Pin_4 , PIO_Pin_0},
{GPIO_Pin_7, GPIO_Pin_3 , GPIO_Pin_1},
{GPIO_Pin_0, GPIO_Pin_15, GPIO_Pin_2}};
trace not_trace_groups[NUM_TRACES][NUM_TRACES];
void main()
{
for (int i = 0; i < NUM_TRACES; i++)
{
not_trace_group[i] = {all_traces[i], all_traces[(i+1)%NUM_TRACES], all_traces[(i+2)%NUM_TRACES], all_traces[(i+3)%NUM_TRACES], all_traces[(i+4)%NUM_TRACES], all_traces[(i+5)%NUM_TRACES])};
}
while(1 == 1){
for (int i = 0; i < NUM_TRACES; i++)
{
trace_test(not_trace_group[i]);
}
}
void trace_test(trace cur_trace, trace not_trace1, trace not_trace2, trace not_trace3, trace not_trace4, trace not_trace5)
{
// do some stuff
}
I 수신 오류 :
error: expected expression before '{' token
not_trace_group[i] = {all_traces[i], all_traces[(i+1)%NUM_TRACES], all_traces[(i+2)%NUM_TRACES], all_traces[(i+3)%NUM_TRACES], all_traces[(i+4)%NUM_TRACES], all_traces[(i+5)%NUM_TRACES])};
I는 I 배열의 두 번째 레벨 그래서이 시도 할 수 assignto 아마도 생각
:
trace not_trace_groups[NUM_TRACES];
을하지만 이는 범 같은 오류
typedef에서 초기화 할 수 없습니다. 어쨌든 모든 프로그램은 C로 작성되지 않습니다. –
이것은 다소 모호 합니다만, 함수에 배열을 건네주는 것이 도움이되는 것처럼 보일 것입니다. (size_t i = 0; i
Lundin
'trace_test'는 6 개의 인수를 취하지 만 1 개만 제공했습니다. 또한 배열에 할당 할 수 없습니다. –