Yevgen Muntyan wrote:
[...]
X events example). It's also true that what your example is
completely off-topic here, even more off-topic than usual, since you
are saving/loading structure content and that's non-portable, breaks
across implementations, may break even on the same implementation, etc.
Just because the data file generated by a particular program is
not portable does not mean that the program itself isn't. (After
all, one could argue that a simple fprintf(out,"Hello, world.\n")
isn't "portable" in that the file it generates depends on the
particular character set and EOL sequence of the platform.) If
a program can write something to a file, and then later read the
same file and get the same information, it doesn't really matter
if that file can't be taken to a different platform and read by
the same program compiled on the other platform. (At least not
as far as standard C is concerned. The developer/end-user may
be concerned about data-file portability, but that a different
matter entirely.)
If you use fwrite() to save a float to a binary stream, and later
in the program use fread() on that same stream (assuming that the
file position is the same), aren't you guaranteed to get the same
float value back? (Assuming nothing else has modified the file,
and the fread succeeds, of course.)
Kenny made a good point about it, perhaps not in the best form, but
that's Kenny, "admitted troll it's best to ignore him" as some say. The
OP was very lucky that "regulars" were in good mood, or maybe common
sense worked in this case for some reason. Or perhaps they interpreted
it as "what are strictly-conforming examples of using union", which
is unlikely to be what OP asked about.
I don't think there's anything OT about writing unions to develop
a messaging interface, or other system-specific things like a GUI
interface. Naturally, the implementation of the messages, events,
and GUI itself are OT here, but I don't think an interface to such
things are OT.
For example:
Ignoring the actual GUI specifics, could I use a union of
structs to implement a generic "draw this shape" interface?
Yes, you could to that in 100% "standard C" and be on-topic for
clc.
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:
[email protected]>