This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/CCSTUDIO: #1231-D variable-length array field type will be treated as zero-length array field type

Part Number: CCSTUDIO


Tool/software: Code Composer Studio

ide: CCS v8.2.0

compiler: TI v5.2.5

chip: am3552

snippet:

while(1)
	{
		frameLen = my_recv_UDP(AS_UDP_Dev_Health_socket, rxBuf, sizeof(rxBuf), (struct sockaddr*)&ra, sizeof(ra));
		if(frameLen <= 0){
			OSTimeDlyHMSM(0, 0, 1, 0,OS_OPT_TIME_HMSM_STRICT,&err);
			continue;
		}
		pktLen = (rxBuf[1] >> 8)+(rxBuf[2]);	//packet len
		dataLen = pktLen - 24;					//data len
		typedef struct
		{
			u8 buf[24+dataLen];
			union{
				u8 stx;
				u8 len[2];
				union{
					u8 low;
					u8 high;
				}cmdlen;
				u8 pid;
				u8 seriID;
				u8 cmdID[2];
				u8 cmdVer;
				u8 srcIDInfo[7];
				u8 destIDInfo[7];
				u8 data[dataLen];
				u16 cksum;
			}rxBuf;
		}rxBuf_s;
		rxBuf_s* rxBuf_p = (rxBuf_s*)&rxBuf[0];

/*following code is omitted*/

Hello.

I'm dealing with socket programming and here is a udp example.

Because one doesn't know how many data in udp frame until receive it, I only can decide array length after receiving it.

This array is so-called variable-length array, introduced in C99.

It seems that this compiler version doesn't support it.

I've read this article: https://e2e.ti.com/support/tools/ccs/f/81/t/297429?Variable-length-arrays-and-MSP430-compiler

It says variable length array is supported by compiler since 4.2.0 when the --gcc option is used.

Where can I find this setting of gcc option? Thank you.

  • VLA = variable length array

    Andy Lin94 said:
    This array is so-called variable-length array, introduced in C99.

    Correct.  However, VLAs are not allowed within structs.  In the C99 ANSI standard section 6.7.5.2, paragraph 2, it says ...

    Only an ordinary identifier (as defined in 6.2.3) with both block scope or function prototype scope and no linkage shall have a variably modified type.  

    A struct member is not an ordinary identifier.  When I compile your code example with a recent version of the TI ARM compiler that supports C99, and use the options --c99 --strict_ansi, then the VLAs get error diagnostics.  

    When I compile your example with compiler version 5.2.5 (without the options --c99 --strict_ansi), both the VLAs get this warning diagnostic ...

    warning: variable-length array field type will be treated as zero-length array field type

    I find this confusing.  I understand what it means for a zero-length array to be at the end of a struct.  But not in the middle of other members.  Something is not right.  So I filed CODEGEN-5700 in the SDOWP system to have this investigated.  You are welcome to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George