linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Micha Feigin <michf@post.tau.ac.il>
To: linux-c-programming@vger.kernel.org
Subject: Re: value computed is not used ??
Date: Thu, 3 Jun 2004 04:26:47 +0300	[thread overview]
Message-ID: <20040603012647.GB2562@luna.mooo.com> (raw)
In-Reply-To: <16572.64502.651803.95029@cerise.nosuchdomain.co.uk>

On Tue, Jun 01, 2004 at 10:58:14PM +0100, Glynn Clements wrote:
> 
> 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

On the other hand it allows you to check for pointer initialization
later to see if you already put a meaningful value in it, and in big
programs there is more use for that then the chance of a compiler error
by using an uninitialized value (especially since a debugger will catch
that in a second).

> segfault (or, on an architecture which doesn't have an MMU, just
> incorrect behaviour) at run time.
> 

You have much worse head aches on MMU-less systems then accessing a NULL
initialized pointer, from experience ;-) (although it is a method the
kernel uses to generate and exception locking up the system on panic)

On the other hand what are the chances of him running into an mmu-less
system considering its only a few embedded systems that are not using an
MMU these days.

> 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>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>  
>  +++++++++++++++++++++++++++++++++++++++++++
>  This Mail Was Scanned By Mail-seCure System
>  at the Tel-Aviv University CC.
> 

  reply	other threads:[~2004-06-03  1:26 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
2004-06-03  1:26             ` Micha Feigin [this message]
  -- 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=20040603012647.GB2562@luna.mooo.com \
    --to=michf@post.tau.ac.il \
    --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).