🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3345

Re: Struct hack one last time (one last time)

#3345
From: Steve Clamage
Date: Fri, 08 Jan 1993 18:43
29 lines
1690 bytes
flaps@dgp.toronto.edu (Alan J Rosenthal) writes:

>steve@taumet.com (Steve Clamage) writes:
>>An implementation is allowed to add padding to the end of a struct.
>>Suppose that the implementation adds space to the end of each struct
>>type where it encodes information used for run-time error checking.

>Can't do that... what happens when you malloc one of them?

>	struct whatever *p = (struct whatever *)malloc(sizeof(struct whatever));

>Immediately after the malloc, if p is not null you can start using the struct,
>but it won't have that run-time-error-checking information, so it will fault.

The compiler is allowed to recognize calls to standard library functions.
It could fix up the returned struct after the call to malloc (or realloc
or calloc).  It would also have to interpret the size in case an array
were being allocated:
	extern size_t s;
	struct w *p = malloc(s);
	/* fixup s/sizeof(struct w) structs here */

You could subvert this via void* pointers, but that isn't the point.
Presumably this is an optional checkout mode, and such modes typically
impose constraints on programmers.  If you play games to subvert type
checking, you are going to have problems.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Technical Details
Message-ID: <1993Jan8.184304.10965@taumet.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!taumet!steve
References: <1992Dec31.153931.7495@hubcap.clemson.edu> <1993Jan1.173852.26630@taumet.com> <1993Jan7.145117.8220@jarvis.csri.toronto.edu>

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: Struct hack one last time (one last time)
Message-ID: <1993Jan8.184304.10965@taumet.com>
Organization: TauMetric Corporation
References: <1992Dec31.153931.7495@hubcap.clemson.edu> <1993Jan1.173852.26630@taumet.com> <1993Jan7.145117.8220@jarvis.csri.toronto.edu>
Date: Fri, 8 Jan 1993 18:43:04 GMT
Lines: 29