🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #858

Re: hiding lint's ravings (was Re: FAQ - malloc array - clarify)

#858
From: Dave Martindale
Date: Fri, 14 Sep 1990 03:45
25 lines
1836 bytes
In article <2985@anasaz.UUCP> duane@anasaz.UUCP (Duane Morse) writes:
>Here are two suggestions to remove lint's pointer alignment complaint.
>
>2) Write your own "malloc" subroutine which returns 0 for success and
>a nonzero value for failure; pass a pointer to where you want to store
>the address and have the routine interpret it as a char **; use a
>variable of the type you really need (struct whatever *) and cast it
>to (char **) in the subroutine call -- lint won't complain about any
>of this.

This is a BAD idea.  If you are on a machine where a byte and (short,
int, long, float, double) pointers do not have the same representation,
this won't work.  When you declare the "extra" allocator argument
as a char **, and then store the memory address via it, the memory
allocator will always store the address in char * format - it doesn't
know what actual type of pointer you want to use.

In contrast, even though lint complains, when you use malloc in the
normal way, the C compiler knows that malloc is returning a char *
and you want a different type of pointer, and will generate code to
do the conversion if any is needed on this machine.

So, your suggestion gets rid of the lint complaint, but gives code
that is no longer portable.  If I were marking such an assignment,
I'd mark that as an error.
Technical Details
Message-ID: <1990Sep14.034528.23234@imax.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!geac!alias!imax!dave
References: <1990Sep08.022034.8444@virtech.uucp> <8086@helios.TAMU.EDU> <2985@anasaz.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!geac!alias!imax!dave
From: dave@imax.com (Dave Martindale)
Newsgroups: comp.unix.programmer
Subject: Re: hiding lint's ravings (was Re: FAQ - malloc array - clarify)
Keywords: malloc, Sun, lint
Message-ID: <1990Sep14.034528.23234@imax.com>
Date: 14 Sep 90 03:45:28 GMT
References: <1990Sep08.022034.8444@virtech.uucp> <8086@helios.TAMU.EDU> <2985@anasaz.UUCP>
Organization: Imax Systems Corporation, Oakville Canada
Lines: 25