1)preprocessor warning ,2) argv[0]..btw, my first mail to clc :-)

V

vinayby

hi all,
two doubts
1) in this code.. one might pass FUNC(x) definition externally..

#ifdef FUNC(x)
double fnew(double x){
return FUNC(x);
}
#endif

but i get a warning..(things work nice though)
=>warning: extra tokens at end of #ifdef directive

why is it so.. and how can one get rid of this..

2) I was wondering if it was possible to change argv[0] during
runtime.. so that
he process table show the newname rather than say "a.out"
OR is it OSdependent


PS:.. c.l.c is cool !
 
E

Emmanuel Delahaye

vinayby a écrit :
1) in this code.. one might pass FUNC(x) definition externally..

#ifdef FUNC(x)
double fnew(double x){
return FUNC(x);
}
#endif

This is incorrect. You want

#ifdef FUNC
double fnew(double x)
{
return FUNC(x);
}
#endif

assuming that the FUNC() macro is defined before.
2) I was wondering if it was possible to change argv[0] during
runtime...

Yes, it is.

Just be careful what your are doing. argv points to an array of pointers
to char. You can decide to make argv[0] point elsewhere:

argv[0] = "My smart name";

but don't use strcpy(),

strcpy(argv[0], "My smart name"); /* WRONG! */

because you know nothing about the space pointetd by argv[0].
he process table show the newname rather than say "a.out"
OR is it OSdependent

What about giving your executable a better name ? Read your
compiler/lnker documentation for details.
 
M

Michael Mair

Emmanuel said:
vinayby a écrit :
2) I was wondering if it was possible to change argv[0] during
runtime...

Yes, it is.

Just be careful what your are doing. argv points to an array of pointers
to char. You can decide to make argv[0] point elsewhere:

argv[0] = "My smart name";

but don't use strcpy(),

strcpy(argv[0], "My smart name"); /* WRONG! */

because you know nothing about the space pointetd by argv[0].

This is wrong. One may change argv as it is not const-qualified
and one may change the strings pointed to by argv, i < argc,
because the standard allows it. So, snprintf() or strncpy()
restricted by the original length of the string pointed to by
argv[0] is the right answer.
See the thread starting at

This is not necessarily possible. argv[0] may point to a copy
of the name at the start of the program.
So, OS dependent means are probably necessary.


Cheers
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,186
Latest member
vinaykumar_nevatia

Latest Threads

Top