Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Tim Rentsch <txr@alumni.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Questions Regarding Null and Casting |
| Date | 2011-06-03 20:45 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <kfnboyeuun4.fsf@x-alumni2.alumni.caltech.edu> (permalink) |
| References | <isbl3d$lvh$1@speranza.aioe.org> <lntyc6imc4.fsf@nuthaus.mib.org> |
Keith Thompson <kst-u@mib.org> writes:
> BigChuck19 <bc19@mailinator.com> writes:
>[snip]
>
>> My question concerns the use of the cast (int *). The book states
>> that one must write " if (grades == (int *) NULL) " because if there
>> is insufficient memory available, malloc() returns NULL, which is then
>> cast into a pointer to an integer by the (int *) preceding the call to
>> malloc().
>
> The cast is an explicit conversion. It's unnecessary because the value
> of NULL will be implicitly converted to the type of grades (int*) before
> it's compared. [snip]
Just an amusing note here. 6.5.9p4 says:
Otherwise, at least one operand is a pointer. If one
operand is a pointer and the other is a null pointer
constant, the null pointer constant is converted to the type
of the pointer. If one operand is a pointer to an object or
incomplete type and the other is a pointer to a qualified or
unqualified version of void, the former is converted to the
type of the latter.
If NULL is defined as '(void*)0', then both of the last two
sentences apply, and each operand is converted to the type
of the other.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Questions Regarding Null and Casting BigChuck19 <bc19@mailinator.com> - 2011-06-03 21:52 +0000
Re: Questions Regarding Null and Casting Ian Collins <ian-news@hotmail.com> - 2011-06-04 10:13 +1200
Re: Questions Regarding Null and Casting Ian Collins <ian-news@hotmail.com> - 2011-06-04 10:16 +1200
Re: Questions Regarding Null and Casting Keith Thompson <kst-u@mib.org> - 2011-06-03 15:25 -0700
Re: Questions Regarding Null and Casting Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-03 20:45 -0700
Re: Questions Regarding Null and Casting pete <pfiland@mindspring.com> - 2011-06-03 18:38 -0400
Re: Questions Regarding Null and Casting Angel <angel+news@spamcop.net> - 2011-06-03 23:23 +0000
Re: Questions Regarding Null and Casting Keith Thompson <kst-u@mib.org> - 2011-06-03 17:24 -0700
Re: Questions Regarding Null and Casting "J. J. Farrell" <jjf@bcs.org.uk> - 2011-06-04 00:45 +0100
Re: Questions Regarding Null and Casting Keith Thompson <kst-u@mib.org> - 2011-06-03 17:27 -0700
Re: Questions Regarding Null and Casting pete <pfiland@mindspring.com> - 2011-06-03 21:12 -0400
Re: Questions Regarding Null and Casting Shao Miller <sha0.miller@gmail.com> - 2011-06-06 20:11 -0500
csiph-web