* Re: Assignment make pointers
@ 2004-12-13 10:04 r_zaca
2004-12-13 10:10 ` Jan-Benedict Glaw
0 siblings, 1 reply; 11+ messages in thread
From: r_zaca @ 2004-12-13 10:04 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Mail message body --]
[-- Type: text/plain, Size: 1063 bytes --]
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]);
I hope it will help you.
Good luck.
Hello,
New to the list and to C. Read O'Reilly's Practical C Programming and
another C book and am now trying to evolve beyond helloworld.c. When I
compile the snippet below, gcc-3.4.2 on Fedora Core 3 spits out:
test2.c:11: warning: assignment makes pointer from integer without a
cast
test2.c:12: warning: passing arg 1 of `usage' from incompatible pointer
type
I just can't figure out why it does that and how to fix it since my
pointer/casting/C knowledge is definitely lacking. The snippet does work
ok. Anyone care to enlighten me?
#include <stdio.h>
void usage(int *prog_ptr)
{
fprintf(stdout,"progname is: %s\n",*prog_ptr);
}
int main(int argc, char *argv[])
{
int *prog_ptr;
prog_ptr = basename (argv[0]);
usage(&prog_ptr);
return(0);
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Assignment make pointers
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
0 siblings, 1 reply; 11+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-13 10:10 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]
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).
MfG, JBG
--
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 --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Assignment make pointers
2004-12-13 10:10 ` Jan-Benedict Glaw
@ 2004-12-13 14:51 ` Eric Bambach
2004-12-13 14:58 ` Eric Bambach
2004-12-13 15:47 ` Assignment make pointers Jan-Benedict Glaw
0 siblings, 2 replies; 11+ messages in thread
From: Eric Bambach @ 2004-12-13 14:51 UTC (permalink / raw)
To: linux-c-programming; +Cc: Patrick
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Assignment make pointers
2004-12-13 14:51 ` Eric Bambach
@ 2004-12-13 14:58 ` Eric Bambach
2004-12-13 15:01 ` C Newbie Darren Sessions
2004-12-13 15:47 ` Assignment make pointers Jan-Benedict Glaw
1 sibling, 1 reply; 11+ messages in thread
From: Eric Bambach @ 2004-12-13 14:58 UTC (permalink / raw)
To: linux-c-programming
On Monday 13 December 2004 08:51 am, Eric Bambach wrote:
> 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?
Sorry to reply to my own post, but nevermind. Its too early (someone called
and woke me up :) and I've been programming in C++ too long where prototypes
are required. gcc will compile happily without libgen.h while g++ won't. That
answers my own question.
Sorry for the noise.
--
-EB
^ permalink raw reply [flat|nested] 11+ messages in thread
* C Newbie
2004-12-13 14:58 ` Eric Bambach
@ 2004-12-13 15:01 ` Darren Sessions
2004-12-13 15:50 ` Jan-Benedict Glaw
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Darren Sessions @ 2004-12-13 15:01 UTC (permalink / raw)
To: linux-c-programming
I need to know (before I get flamed) if this is an appropriate spot to post
questions on C programming or not and the very most newbie level. I'm
attempting a transition from Perl and, while I understand a lot of the
fundamentals of C, am having a hard time with string (char) manipulation.
Thanks,
- Darren
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Assignment make pointers
2004-12-13 14:51 ` Eric Bambach
2004-12-13 14:58 ` Eric Bambach
@ 2004-12-13 15:47 ` Jan-Benedict Glaw
1 sibling, 0 replies; 11+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-13 15:47 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 772 bytes --]
On Mon, 2004-12-13 08:51:44 -0600, Eric Bambach <eric@cisu.net>
wrote in message <200412130851.44586.eric@cisu.net>:
> What escapes me though is how the compiler could compile without knowing the
> definition. Isnt it REALLY presumptuous and dangerous for the compiler to
The "type defaults to int" thing. This is why the initial writer got an
error message that an int type is about to be converted to pointer type.
MfG, JBG
--
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 --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: C Newbie
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
2 siblings, 0 replies; 11+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-13 15:50 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]
On Mon, 2004-12-13 10:01:28 -0500, Darren Sessions <dsessions@ionosphere.net>
wrote in message <BDE318F8.1618%dsessions@ionosphere.net>:
> I need to know (before I get flamed) if this is an appropriate spot to post
> questions on C programming or not and the very most newbie level. I'm
> attempting a transition from Perl and, while I understand a lot of the
> fundamentals of C, am having a hard time with string (char) manipulation.
Start asking. However, start a question with a new email, not by
pressing you email client's "reply" button and deleting any old text.
Hijacking threads is bad habit and makes proper email sorting a hard
challange...
MfG, JBG
--
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 --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: C Newbie
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
2 siblings, 0 replies; 11+ messages in thread
From: Eric Bambach @ 2004-12-13 16:03 UTC (permalink / raw)
To: Darren Sessions; +Cc: linux-c-programming
On Monday 13 December 2004 09:01 am, you wrote:
> I need to know (before I get flamed) if this is an appropriate spot to post
> questions on C programming or not and the very most newbie level. I'm
> attempting a transition from Perl and, while I understand a lot of the
> fundamentals of C, am having a hard time with string (char) manipulation.
>
> Thanks,
>
> - Darren
As JBG advised yes please don't hijack threads. It confuses me AND my mailer.
Other than that I would be happy to assist on the list if I can, even though
my programming skills aren't great yet. My advice is to limit your questions
though. Try to do most of the reasearch off list and ask specifc questions
when something stumps you or doesnt work as expected after you've tried to
debug it yourself. If it looks like you didn't try (ex. throwing code at us
with the subject it doesnt compile) or cant give us specific code with
questions to help on you're less likely to get any useful information off the
list.
Other than that, I hope I can be of help and I hope the list gurus agree with
me.
--
-EB
^ permalink raw reply [flat|nested] 11+ messages in thread
* Defunct Processes
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 ` Darren Sessions
2004-12-29 10:16 ` Jan-Benedict Glaw
2 siblings, 1 reply; 11+ messages in thread
From: Darren Sessions @ 2004-12-29 2:13 UTC (permalink / raw)
To: linux-c-programming
The application I'm working on right now gets called from another
application. When my program is finished, I just use exit(0); to quit, but
if I do a ps there are a ton of [applicationname] <defunct> messages.
I'm using Suse Enterprise Linux 9.0 with the 2.6 Kernel.
Thanks,
- Darren
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Defunct Processes
2004-12-29 2:13 ` Defunct Processes Darren Sessions
@ 2004-12-29 10:16 ` Jan-Benedict Glaw
2004-12-30 13:14 ` Daniel Souza
0 siblings, 1 reply; 11+ messages in thread
From: Jan-Benedict Glaw @ 2004-12-29 10:16 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]
On Tue, 2004-12-28 21:13:56 -0500, Darren Sessions <dsessions@ionosphere.net>
wrote in message <BDF77D14.1AE7%dsessions@ionosphere.net>:
> The application I'm working on right now gets called from another
> application. When my program is finished, I just use exit(0); to quit, but
> if I do a ps there are a ton of [applicationname] <defunct> messages.
This is a fault of the calling application. Your program became a
zombie. That's the remaining rest of a process that already finished.
(Basically, it consists of accounting information, the process' exit
value and probably of the signal number that led to the process' death).
This information needs to be handled (the parent process needs to wait()
or wait4() it, or using other methods). Normally, the parent process
should handle the SIGCHLD signal; it's generated upon a child's death.
This would allow the parent to call wait() as long as there are finished
childs (remember, you only know the signal got fired, but you don't know
how often :) Calling wait() then will finally bury the finished child.
MfG, JBG
--
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 --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Defunct Processes
2004-12-29 10:16 ` Jan-Benedict Glaw
@ 2004-12-30 13:14 ` Daniel Souza
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Souza @ 2004-12-30 13:14 UTC (permalink / raw)
To: linux-c-programming
you can
signal(SIGCHLD, SIG_IGN);
to ignore childs termination notifications, so, the parent dont need
to wait() for childs, they just go without any parent notification,
and no zombies.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-12-30 13:14 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).