struct tm

A

aegis

Under c90, not c99, where is the behavior
outlined for memset zeroing such an
object of this struct type? I know
under c99 you have the possibility
of creating a trap representation or
raising an implementation defined signal
but what about c90?
 
R

Richard Bos

aegis said:
Under c90, not c99, where is the behavior
outlined for memset zeroing such an
object of this struct type? I know
under c99 you have the possibility
of creating a trap representation or
raising an implementation defined signal
but what about c90?

Note 122 (in the definition of memcmp()) refers to the memset()ing of
struct objects as if it were no problem, and I can find no reason to
suspect otherwise. Therefore, I assume that memset()ing the alignment
and padding bytes in a struct has no impact on the struct's validity
(after all, they are otherwise indeterminate anyway); and that doing so
to any declared struct members is as valid as if they had been normal
objects instead of struct members. So memset()ing unsigned chars struct
members is certainly valid, and memset()ing float struct members only
depending on the floating point model the implementation uses.

Richard
 
R

Richard Heathfield

aegis said:
Under c90, not c99, where is the behavior
outlined for memset zeroing such an
object of this struct type?

Everything in it is an int, so you're in the clear. It isn't actually
possible AFAIK to prove from C90 that memsetting (to 0) an aggregate
object containing only integral types will give each of them the value
0, but IIRC according to ISO there are *no* implementations where it
doesn't. I'd give references if I had them. Perhaps someone from ISO
can clarify.
I know under c99 you have the possibility
of creating a trap representation or
raising an implementation defined signal

I don't think so, actually - not for 0.
but what about c90?

I consider myself a rather conservative C programmer, and I regularly
blast an entire memset's-worth of 0s right through my integer-only
aggregate data structures. Not terribly often, though - and, to be
precise, not all that regularly either. But sometimes, anyway. What
*is* the word? Ah! Fearlessly. I fearlessly use memset to 'zero out'
integer-only aggregate data structures. Despite the fact that I haven't
a clue what platforms my code will be run on.

Of course, if there are pointers or floaty-pointy thingies around,
that's a different matter.
 
C

CBFalconer

aegis said:
Under c90, not c99, where is the behavior outlined for memset
zeroing such an object of this struct type? I know under c99 you
have the possibility of creating a trap representation or raising
an implementation defined signal but what about c90?

Totally incomprehensible without proper quoting. What struct
type? What object? See the reference in my sig. below.

--
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>
 
E

Eric Sosman

Richard Heathfield wrote On 06/21/07 06:43,:
aegis said:

Under c90, not c99, where is the behavior
outlined for memset zeroing such an
object of this struct type?


Everything in it is an int, so you're in the clear. [...]

Nitpick: Everything *required* to be in it is an int.
The Standard allows an implementation's struct tm to have
elements other than those listed, and the types of any
extra elements could be whatever the implementation liked.

Personally, I'd just initialize at declaration:

struct tm when = { 0 };

If you need to re-clear it after using it (why?), memset
is very likely safe. For freedom from all possible worry:

static const struct tm zero = { 0 };
struct tm when;
...
when = zero; /* instead of memset */
... fill it in and use it ...
when = zero;
... play it again, Sam ...
 
C

CBFalconer

Richard said:
CBFalconer said:

Quoting of what, Chuck? He's the OP!

What is happening to you?

I virtually never look at the subject. I suspect he constructed a
new thread out of a reply to something else.
 
K

Keith Thompson

CBFalconer said:
I virtually never look at the subject. I suspect he constructed a
new thread out of a reply to something else.

That doesn't appear to be the case. If there's insufficient context,
I suggest that you *should* look at the subject before jumping to
conclusions.
 
F

Flash Gordon

Keith Thompson wrote, On 22/06/07 03:53:
That doesn't appear to be the case.

I just checked and there were no references headers, so it definitely
was not the case.
> If there's insufficient context,
I suggest that you *should* look at the subject before jumping to
conclusions.

Chuck, you should definitely check before claiming someone should quote
context. Complaining at the OP for not putting all of the information in
the message would be valid, but that is not the complaint made.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top