Article View: comp.lang.c.moderated
Article #2542Re: What are some tricky C questions?
From: Lawrence Kirby
Date: Mon, 08 Apr 1996 16:08
Date: Mon, 08 Apr 1996 16:08
47 lines
2055 bytes
2055 bytes
In article <4k611a$aln@solutions.solon.com>
clgonsal@undergrad.math.uwaterloo.ca
"Carl Laurence Gonsalves" writes:
> >Very little since MAXINT isn't defined. :-) Perhaps if you were to include
> >limits.h and use INT_MAX instead. If you want to add a bit of interest to
> >the problem you could ask the same question about:
> >
> >#include <stddef.h>
> >#include <limits.h>
> >
> > size_t l;
> > short i = SHRT_MAX;
> >
> > l = sizeof(++i);
>
>Whatever the case, one can always say l==sizeof(i) (the actual numerical
>value is implementation dependant),
Right (at least where i is a scalar). Compare that with:
l = sizeof(+i);
to see the possible pitfall.
>and i remains unchanged from it's
>initial value, whether that's MAXINT, INT_MAX, SHRT_MAX, FOO, 5, etc.
or even uninitialised.
>I think the original poster's point was that the above code does not change
>the value of i, which is not obvious unless you know that sizeof does not
>evaluate it's operand.
No doubt! Some other curious examples are:
l = sizeof(i/0);
l = sizeof sizeof i;
int a[10];
l = sizeof a[100];
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID:
<4kbdlo$e9t@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jol5v$1qs@solutions.solon.com> <4jttdi$3jm@solutions.solon.com> <4k1pks$514@solutions.solon.com> <4k611a$aln@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: Lawrence Kirby <fred@genesis.demon.co.uk> Newsgroups: comp.lang.c.moderated Subject: Re: What are some tricky C questions? Date: 8 Apr 1996 11:08:24 -0500 Organization: none Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4kbdlo$e9t@solutions.solon.com> References: <4jol5v$1qs@solutions.solon.com> <4jttdi$3jm@solutions.solon.com> <4k1pks$514@solutions.solon.com> <4k611a$aln@solutions.solon.com> Reply-To: fred@genesis.demon.co.uk NNTP-Posting-Host: solutions.solon.com X-NNTP-Posting-Host: genesis.demon.co.uk X-Newsreader: Demon Internet Simple News v1.27 X-Mail2News-Path: genesis.demon.co.uk