which is const in "char *const argv[]"

E

Eric

Hi
For this code,
int getopt (int argc, char *const argv[], const char *opts)
what does the "char *const argv[]" mean? Does it equal to "char **const
argv"?
Or "char *const *argv"? Which is the const?

Thanks
 
M

Michael Mair

Eric said:
For this code,
int getopt (int argc, char *const argv[], const char *opts)
what does the "char *const argv[]" mean? Does it equal to "char **const
argv"?
Or "char *const *argv"? Which is the const?

char * const * argv.
I suggest that you get yourself a little programme called cdecl:
,---
$ cdecl
Type `help' or `?' for help
cdecl> explain char *const argv[]
declare argv as array of const pointer to char
cdecl> explain char *const *argv
declare argv as pointer to const pointer to char
`---
which of course is equivalent for function parameters

Cheers
Michael
 
J

John Bode

Eric said:
Hi
For this code,
int getopt (int argc, char *const argv[], const char *opts)
what does the "char *const argv[]" mean? Does it equal to "char **const
argv"?
Or "char *const *argv"? Which is the const?

Thanks

char * const * argv -- argv is a pointer to a const pointer to char;
essentially, argv is an array of const pointers.
 
L

lovecreatesbeauty

Michael said:
I suggest that you get yourself a little programme called cdecl:

cdecl seems no much help, e.g.:

cdecl> explain void (*signal(int sig, void (*func)(int)))(int);
parse error
cdecl> explain int main(int argc, char *argv[]);
parse error
cdecl> explain int main(void);
declare main as function (void) returning int
cdecl>

lovecreatesbeauty
 
G

Guest

lovecreatesbeauty said:
Michael said:
I suggest that you get yourself a little programme called cdecl:

cdecl seems no much help, e.g.:

cdecl> explain void (*signal(int sig, void (*func)(int)))(int);
parse error
cdecl> explain int main(int argc, char *argv[]);
parse error
cdecl> explain int main(void);
declare main as function (void) returning int
cdecl>

cdecl doesn't properly support function prototypes. Its manpage tells
me that's because it was written before C89 was completed. Try it
without the parameter names:

cdecl> explain void (*signal(int, void (*)(int)))(int)
declare signal as function (int, pointer to function (int) returning
void) returning pointer to function (int) returning void
 
L

lovecreatesbeauty

Harald said:
cdecl doesn't properly support function prototypes. Its man page tells
me that's because it was written before C89 was completed. Try it
without the parameter names:

Ok, following is the version information about cdecl on my Debian
Linux. Perhaps the year C89 was released is earlier than the year when
cdecl at 2.5 1/15/96. :)

$ pwd
/home/jhl/cdecl_2.5-6_i386
$ cdecl -V
Version:
@(#)cdecl.c 2.5 1/15/96
@(#)cdgram.y 2.2 3/30/88
@(#)cdlex.l 2.2 3/30/88
$

lovecreatesbeauty
 
D

Dik T. Winter

....
> Ok, following is the version information about cdecl on my Debian
> Linux. Perhaps the year C89 was released is earlier than the year when
> cdecl at 2.5 1/15/96. :)
>
> $ pwd
> /home/jhl/cdecl_2.5-6_i386
> $ cdecl -V
> Version:
> @(#)cdecl.c 2.5 1/15/96
> @(#)cdgram.y 2.2 3/30/88
> @(#)cdlex.l 2.2 3/30/88
> $

Probably a minor bugfix compared to:
@(#)cdecl.c 2.4 3/31/88
But note the date of cdlex (which does the parsing).
 
E

Eric

Uh ah, cdecl is really an interesting programme! Thanks.

Michael said:
Eric said:
For this code,
int getopt (int argc, char *const argv[], const char *opts)
what does the "char *const argv[]" mean? Does it equal to "char **const
argv"?
Or "char *const *argv"? Which is the const?

char * const * argv.
I suggest that you get yourself a little programme called cdecl:
,---
$ cdecl
Type `help' or `?' for help
cdecl> explain char *const argv[]
declare argv as array of const pointer to char
cdecl> explain char *const *argv
declare argv as pointer to const pointer to char
`---
which of course is equivalent for function parameters

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top