Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <4F3176ED.3080503@loria.fr> (permalink) |
|---|---|
| Date | 2012-02-07 20:09 +0100 |
| From | Jens Gustedt <jens.gustedt@loria.fr> |
| Newsgroups | comp.lang.c |
| Subject | Re: a = b or memset/cpy? |
| References | <abb85a15-f68c-4e2f-8985-fe8b4945aca0@t8g2000yqg.googlegroups.com> <4F316233.2040208@loria.fr> <4F31703B.1070003@verizon.net> |
| Organization | Guest of ProXad - France |
Am 02/07/2012 07:40 PM, schrieb James Kuyper:
> On 02/07/2012 12:41 PM, Jens Gustedt wrote:
>> On any decent compiler the assignment version should not be worse that
>
> This is initialization, not assignment.
No, you are mistaken. The relevant part is assignment to gX[slot]. The
other part is just initialization of a const. In particular the
initialization of the const qualified compound literal can be done at
compile time if the compiler decides that it is beneficial (as if it
where declared as a static variable).
>> the memset version, because the compiler must be able to see that it
>> is an object only filled with 0.
>
> I've used a compiler which, given the following code:
>
> double array[10][1354][3] = {0};
>
> generated the equivalent of the following:
>
> array[0][0][0] = 0;
> array[0][0][1] = 0;
> etc.
> The resulting executable was noticeably larger that I had expected it to
> be. I was a little annoyed when I figured out what was going on. I
> changed it to use memset(), and got a lot smaller, and executed somewhat
> faster, too. The support person I talked with said that my use of {0}
> was unreasonable, not their compiler's code generation.
How long ago and what compiler was that? My observation over the last
years is that a compiler like gcc is capable of optimizing assignments
to struct fields or different array members as if all of these were
different variables.
(and double may be special, setting all bytes to 0 and initializing
with 0 must not necessarily be the same thing.)
Jens
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a = b or memset/cpy? nroberts <roberts.noah@gmail.com> - 2012-02-07 09:02 -0800
Re: a = b or memset/cpy? Jens Gustedt <jens.gustedt@loria.fr> - 2012-02-07 18:41 +0100
Re: a = b or memset/cpy? James Kuyper <jameskuyper@verizon.net> - 2012-02-07 13:40 -0500
Re: a = b or memset/cpy? Jens Gustedt <jens.gustedt@loria.fr> - 2012-02-07 20:09 +0100
Re: a = b or memset/cpy? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-07 11:37 -0800
Re: a = b or memset/cpy? Shao Miller <sha0.miller@gmail.com> - 2012-02-07 18:35 -0500
Re: a = b or memset/cpy? nroberts <roberts.noah@gmail.com> - 2012-02-07 11:07 -0800
Re: a = b or memset/cpy? blp@cs.stanford.edu (Ben Pfaff) - 2012-02-07 11:14 -0800
Re: a = b or memset/cpy? nroberts <roberts.noah@gmail.com> - 2012-02-07 11:41 -0800
Re: a = b or memset/cpy? Shao Miller <sha0.miller@gmail.com> - 2012-02-07 18:39 -0500
Re: a = b or memset/cpy? "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2012-02-07 14:14 -0500
Re: a = b or memset/cpy? Shao Miller <sha0.miller@gmail.com> - 2012-02-07 18:58 -0500
Re: a = b or memset/cpy? Shao Miller <sha0.miller@gmail.com> - 2012-02-07 21:58 -0500
Re: a = b or memset/cpy? Jens Gustedt <jens.gustedt@loria.fr> - 2012-02-09 21:34 +0100
Re: a = b or memset/cpy? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-07 20:34 -0500
Re: a = b or memset/cpy? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-08 18:43 +0000
Re: a = b or memset/cpy? jgk@panix.com (Joe keane) - 2012-02-08 20:05 +0000
Re: a = b or memset/cpy? Ian Collins <ian-news@hotmail.com> - 2012-02-09 09:18 +1300
Re: a = b or memset/cpy? Tim Prince <tim@nospamcomputer.org> - 2012-02-14 08:30 -0500
csiph-web