From: Eric Bambach <eric@cisu.net>
To: linux-c-programming@vger.kernel.org
Cc: Patrick <patrickC@puzzled.xs4all.nl>
Subject: Re: Assignment make pointers
Date: Mon, 13 Dec 2004 08:51:44 -0600 [thread overview]
Message-ID: <200412130851.44586.eric@cisu.net> (raw)
In-Reply-To: <20041213101011.GO16958@lug-owl.de>
On Monday 13 December 2004 04:10 am, Jan-Benedict Glaw wrote:
> On Mon, 2004-12-13 08:04:32 -0200, r_zaca <r_zaca@ig.com.br>
> wrote in message <20041213_100432_025782.r_zaca@ig.com.br>:
> Content-Description: Mail message body
>
> > If you take a look in "man 3 basename", you'll see that basename
> > function just returns a pointer to a char. In the case above you need to
> > "cast" the pointer returned to be of type int.
> > Like: prog_ptr = (int *) basename (argv[0]);
>
> Don't do that. Usually, you can write even quite large programs without
> using casts at all. Most of the time, a cast points to spots in your
> programs that are badly designed from the type of your variables point
> of view. If your variables are of senseful types and obey a well-thought
> structure (like using enums and unions instead of #defines and casts),
> you usually don't need to cast.
> Also, I usually suggest to compile code with "-Wall" -- that'll show you
> probably lots of odd constructs that should be written differently (or
> using proper types).
True enough. The problem intrigued me enough that I test compiled with -Wall
and the compiler complains of an implicit declaration of basename. It seems
he was missing #include <libgen.h>. Adding this cleared everything up.
What escapes me though is how the compiler could compile without knowing the
definition. Isnt it REALLY presumptuous and dangerous for the compiler to
assume function definitions? I assume basename is in the standard c library
though or it certainly wouldnt link. Can anyone with more experience
elaborate?
> MfG, JBG
--
-EB
next prev parent reply other threads:[~2004-12-13 14:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-13 10:04 Assignment make pointers r_zaca
2004-12-13 10:10 ` Jan-Benedict Glaw
2004-12-13 14:51 ` Eric Bambach [this message]
2004-12-13 14:58 ` Eric Bambach
2004-12-13 15:01 ` C Newbie Darren Sessions
2004-12-13 15:50 ` Jan-Benedict Glaw
2004-12-13 16:03 ` Eric Bambach
2004-12-29 2:13 ` Defunct Processes Darren Sessions
2004-12-29 10:16 ` Jan-Benedict Glaw
2004-12-30 13:14 ` Daniel Souza
2004-12-13 15:47 ` Assignment make pointers Jan-Benedict Glaw
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=200412130851.44586.eric@cisu.net \
--to=eric@cisu.net \
--cc=linux-c-programming@vger.kernel.org \
--cc=patrickC@puzzled.xs4all.nl \
/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).