Deutsch   English   Français   Italiano  
<vvcnm4$2nins$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Muttley@DastardlyHQ.org
Newsgroups: comp.lang.c
Subject: Re: Regarding assignment to struct
Date: Tue, 6 May 2025 10:18:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <vvcnm4$2nins$1@dont-email.me>
References: <vv338b$16oam$1@dont-email.me> <vv4olm$388j7$1@dont-email.me>
 <vv9u4v$46n9$1@dont-email.me> <877c2uhj9l.fsf@nosuchdomain.example.com>
 <vvclpd$2lank$2@dont-email.me>
Injection-Date: Tue, 06 May 2025 12:18:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dfa49597f65451004eb49447431b53ab";
	logging-data="2870012"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19AGL8oLy6KKJCLNH42VW8G"
Cancel-Lock: sha1:4cNyYPudGrR+EMfeHBuaU1F5hEI=

On Tue, 6 May 2025 11:46:21 +0200
David Brown <david.brown@hesbynett.no> wibbled:
>On 05/05/2025 22:53, Keith Thompson wrote:
>> Muttley@dastardlyhq.com writes:
>> [...]
>>> If you twant o pass an actual array to a function instead of a pointer to
>it,
>>> embedding it in a structure is the only way to do it.
>> 
>> Yes, but that's not necessarily useful.  An array that's a member
>> of a struct can only be of a constant length (unless it's a flexible
>> array member, but that doesn't help).  Functions that work with
>> arrays typically need to deal with arrays of arbitrary length.
>> 
>
>I regularly use arrays with known fixed sizes.  In fact, in my code 
>those are absolutely dominant - it is very rare for me to see or use an 
>array whose size is /not/ fixed at compile time.  Sometimes I will have 

I do a lot of networking code and with packet structures the arrays are
almost always of fixed size. Also with arrays the data is inline so a simple
memcpy() can copy the data from the struct to the output buffer. You can't
do that if you have pointers in the struct. Ditto a simple cast to char * to
use it directly as the ouput.