Article View: comp.std.c
Article #81Re: Scalars and Structs
From: Steve Clamage
Date: Mon, 03 Aug 1992 15:25
Date: Mon, 03 Aug 1992 15:25
22 lines
1016 bytes
1016 bytes
edelson@goudurix.inria.fr (Daniel Edelson) writes: >|> Am I correct in taking this to mean that there is no way to cast a >|> structure of known size to a scalar that just so happens to have the same >|> size (or vice versa)? >There's always: > struct S s; > int i; > i = *(int*)&s; As I pointed out in an earlier article, this will fail at runtime if 'int' requires stricter alignment than 'struct S'. For example, ints require 4-byte alignment on some common machines, whereas a struct containing only chars might not require alignment. -- Steve Clamage, TauMetric Corp, steve@taumet.com Vice Chair, ANSI C++ Committee, X3J16
Technical Details
Message-ID:
<1992Aug3.152558.16670@taumet.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!taumet!steveReferences:
<1992Jul30.205601.13276@pasteur.Berkeley.EDU> <4036@seti.UUCP>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!taumet!steve From: steve@taumet.com (Steve Clamage) Subject: Re: Scalars and Structs Message-ID: <1992Aug3.152558.16670@taumet.com> Keywords: casts Organization: TauMetric Corporation References: <1992Jul30.205601.13276@pasteur.Berkeley.EDU> <4036@seti.UUCP> Date: Mon, 3 Aug 1992 15:25:58 GMT Lines: 22