On Fri, 3 Oct 2003 15:40:59 UTC, "Kris Wempa"
<calmincents(NO _SPAM)@yahoo.co m> wrote:
I wasn't implying that it was going to solve all the issues. However, it
comes in handy in many cases and was close to what he was trying to do.
"The Real OS/2 Guy" <os****@pc-rosenau.de> wrote in message
news:wmzsGguTDN 6N-pn2-ctw2npj5F5x2@mo on... On Thu, 2 Oct 2003 17:06:18 UTC, "Kris Wempa"
<calmincents(NO _SPAM)@yahoo.co m> wrote:
Read about the function memcpy(). This function basicalyl copies X number of bytes from one memory location to the other. This should help you
out.
No, it doesn't. An array is NOT a struct. The only you will get is
undefined behavior.
The only you may do is to define a static struct that gets initialised
with a set of default values. You can copy that struct into another my
memcpy. But copying an array into a struct would not work because a
struct may use another set of padding bits than a single variable or
an array uses. Maybe it works in your implementation now - but change
the version of your compiler or any other member of your
implementation and it fails.
It doesn't solve a single issue. using memcpy() for any other type
than (un)signed char is never a solution - except you use for both
bointers objects to the same type. An array is not a single object,
even as itself is a boundle of objects. A struct is not an array even
as you can make an array of struct. A float, int or struct is not an
array of bytes. You may however use a mem...() function to topy one
object of a type to another object of the same type but when you
starts to mixup the types you goes into the lands of undefined
behavior.
Undefined behvior means it can work with the current translation - but
fail with next one, another version of your compiler, another date or
only because it rains or the sun shines. It may work during debug but
will fail in production, it can do anything you expect or ever fail.
It can ever work at moday and ever fail on wednesday, it works on your
burthday but fails on any other day or reverse.
Whenever you have a problem with your data you have decided for a
wrong data layout. You should redesign your data layout. Not only when
your piece of data is object of change you should build a single
module that handles this kind. Then if the change occures rework this
module only and it's done. Make clean interfaces to it and you won.
Programming is a serie of design steps before coding:
- define the whole data layout
- test it, when test fails repeat the previous step
- define you program layout depending on the data layout
- test it, when it fails repeat the steps prior
- define clean interfaces
- test them, when failed repeat with one of the steps above
- write modular code that is able to handle the data
- test it, when failed repeat with one of the prior steps
- write modular code that makes its interaction with the souce of the
data
- test it, when failed repeat with one of the prior steps
- write modular code that makes its interaction with the destination
of the data
- test....
- write modular code that reflects the whole data flow
- test...
- write main() to bind all the modules to bind them right together
- test...
- retest....
- let the DAU test it....
release the program
wait for bug reports
You'll spend more time to get the data model working right than for
all other
You'll spend more time to get the program flow right than for coding
it
You'll spend more time for designing the user interaction than for
coding it
Whenever you starts without a clean and tested data model you'll loose
a multiple of time as when you had spent many time to get it clean
before starting to write the very first statement.
Then you would never come to the problem that you would copy an array
into a structure.
--
Tschau/Bye
Herbert
eComStation 1.1 Deutsch wird jetzt ausgeliefert!