Block Initialization

Pedz Thing pedz at bobkat.UUCP
Tue Oct 14 06:56:02 AEST 1986


In article <586 at calma.UUCP> swang at calma.UUCP (Sin-Yaw Wang) writes:
>What is the most suitable (fast and portable among versions of Unix)
>way to do block initialization?
>

If you have an extra 4k of memory space I do the following:

----------
static struct bigstruct zerobigstruct;

main()
{
  struct bigstruct tobeused;

  tobeused = zerobigstruct;
  ...
}
----------

The above code obviously assumes that the compiler has structure
assignment which I think is a pretty safe assumption if you are
dealing with C compilers on Unix machines.

I realize that this is going to start the big debate about assignment
of structures being either field by field or a block move.  Lets not
get into that argument please.  My point here is if the compiler feels
a block move for the above code is correct then it can produce that.
If the compiler prefers field by field assignment, it can produce
that.  (I personally assume the above code produces a block move and
if that is not what I want, then I must explicitly tell the compiler
otherwise).
-- 
Perry Smith
ctvax ---\
megamax --- bobkat!pedz
pollux---/



More information about the Comp.lang.c mailing list