From mboxrd@z Thu Jan 1 00:00:00 1970 From: rpjday@crashcourse.ca (Robert P. J. Day) Date: Tue, 5 Apr 2016 12:43:48 -0700 (PDT) Subject: variant length array? In-Reply-To: References: Message-ID: To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Tue, 5 Apr 2016, Wenda Ni wrote: > Hi all, > > I come across the following code in a kernel module code. It defines > an array whose length is variant at runtime, depending on the actual > inputs. It seems that kernel compiler supports this, which is > obvious an error in the standard ANSI C. Do I have the correct > understanding on it? > > Thank you. > > > u32 rxe_icrc_hdr(struct rxe_pkt_info *pkt, struct sk_buff *skb) > { > ???????? ... > ???????? int hdr_size = sizeof(struct udphdr) + > ???????????????? (skb->protocol == htons(ETH_P_IP) ? > ???????????????? sizeof(struct iphdr) : sizeof(struct ipv6hdr)); > ???????? u8 tmp[hdr_size + RXE_BTH_BYTES]; > ???????? ... > } pretty sure "sizeof" can be calculated at compile time so i don't see a problem here. rday -- ======================================================================== Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ========================================================================