From: Glynn Clements <glynn.clements@virgin.net>
To: linux-c-programming@vger.kernel.org
Subject: Re: value computed is not used ??
Date: Tue, 1 Jun 2004 22:58:14 +0100 [thread overview]
Message-ID: <16572.64502.651803.95029@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <c9hb7s$3o1$1@sea.gmane.org>
Charlie Gordon wrote:
> > char *ptr = NULL;
> this initialization is useless.
Or possibly worse than useless.
Without the initialisation, if you tried to use it before it was
initialised, the compiler may generate a warning. The above
initialisation would eliminate the warning, and instead result in a
segfault (or, on an architecture which doesn't have an MMU, just
incorrect behaviour) at run time.
Responding to warnings by just "shutting the compiler up" is a common
programming flaw.
Probably the most common situation where this is dangerous is "fixing"
int/long mismatches using a type cast. You can get away with this if
sizeof(int) == sizeof(long) (e.g. i386). But on a system where
sizeof(int) != sizeof(long), the typecast may not work (or, at least,
not correctly), and eliminating the warnings will make it harder to
find (and actually fix) the problems.
--
Glynn Clements <glynn.clements@virgin.net>
next prev parent reply other threads:[~2004-06-01 21:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-23 23:05 functions to determine dementions of console? ameer armaly
2004-05-24 2:09 ` Glynn Clements
2004-05-26 14:41 ` Christoph Bussenius
2004-05-30 19:12 ` J.
2004-05-30 20:35 ` Micha Feigin
2004-05-31 19:38 ` Christoph Bussenius
2004-06-01 1:41 ` value computed is not used ?? J.
2004-06-01 3:25 ` Glynn Clements
2004-06-01 7:30 ` Charlie Gordon
2004-06-01 16:08 ` Charlie Gordon
2004-06-01 21:58 ` Glynn Clements [this message]
2004-06-03 1:26 ` Micha Feigin
-- strict thread matches above, loose matches on Subject: below --
2004-06-01 17:34 Huber, George K RDECOM CERDEC STCD SRI
2004-06-01 19:09 ` Glynn Clements
2004-06-01 20:58 ` Charlie Gordon
2004-06-01 21:44 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16572.64502.651803.95029@cerise.nosuchdomain.co.uk \
--to=glynn.clements@virgin.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).