From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-c-programming@vger.kernel.org
Subject: Re: assignment makes pointer from integer without a cast?
Date: Mon, 13 Dec 2004 20:53:16 +0100 [thread overview]
Message-ID: <20041213195316.GE16958@lug-owl.de> (raw)
In-Reply-To: <20041213161354.GD1487@sweetdream>
[-- Attachment #1: Type: text/plain, Size: 1633 bytes --]
On Mon, 2004-12-13 17:13:54 +0100, Francesco Gadaleta <francesco@gadaleta.org>
wrote in message <20041213161354.GD1487@sweetdream>:
> > void usage(char *prog_ptr) /* not int* */
> > {
> > fprintf(stdout,"progname is: %s\n",prog_ptr); /* not
> > *prog_ptr */
> > }
> >
> > int main(int argc, char *argv[])
> > {
> > char *prog_ptr; /* not int * */
> > prog_ptr = basename (argv[0]);
> > usage(prog_ptr); /* not &prog_ptr */
> > return(0);
> > }
> change this line:
> prog_ptr = basename (argv[0]);
>
> with this:
> prog_ptr = (char*) basename (argv[0]);
No, better include the proper header file <libgen.h> or <string.h>
(after #defining _GNU_SOURCE). This way, you don't force gcc into
guessing it's type. If you had compiled this with a C++ compiler (*), it
wouldn't even had accepted the code or wouldn't link it later on.
MfG, JBG
(*) Compiling not-too-complicated C code with a C++ compiler can reveal
some additional oddities that a pure C compiler wouldn't warn on. So if
you keep your code being compileable with both a C and a C++ compiler
when you start a new project, this won't hurt (but probably pay back at
some time). (-> Right, I'm a C programmer and personally don't use C++
that often, because it's too hard to write "basic" stuff with it).
--
Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 _ O _
"Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg _ _ O
fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2004-12-13 19:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-13 0:52 assignment makes pointer from integer without a cast? Patrick
2004-12-13 1:47 ` Hossein Mobahi
2004-12-13 16:13 ` Francesco Gadaleta
2004-12-13 19:53 ` Jan-Benedict Glaw [this message]
2004-12-16 2:07 ` how to link mqueue library Ron Michael Khu
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=20041213195316.GE16958@lug-owl.de \
--to=jbglaw@lug-owl.de \
--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).