Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does register const char *const *name; mean and why is this variable outside of the function? [duplicate]

Tags:

c

void
usage (cpp)
    register const char *const *cpp;
{
    (void) fprintf (stderr, *cpp++, program_name, cvs_cmd_name);
    for (; *cpp; cpp++)
    (void) fprintf (stderr, *cpp);
    error_exit ();
}

I don't get why register variable is not inside the curly brackets and what is this (void) in front of fprintf? Also register const char *const *cpp, i've never seen anything like this before

like image 857
woowoo Avatar asked Dec 31 '20 21:12

woowoo


People also ask

What is a const char * const *?

const char* const says that the pointer can point to a constant char and value of int pointed by this pointer cannot be changed. And we cannot change the value of pointer as well it is now constant and it cannot point to another constant char.

What is const char * in CPP?

const char *ptr : This is a pointer to a constant character. You cannot change the value pointed by ptr, but you can change the pointer itself. “const char *” is a (non-const) pointer to a const char.

Can a char * be passed as const * argument?

In general, you can pass a char * into something that expects a const char * without an explicit cast because that's a safe thing to do (give something modifiable to something that doesn't intend to modify it), but you can't pass a const char * into something expecting a char * (without an explicit cast) because that's ...

What is static const char?

const char* is a pointer to a constant char, meaning the char in question can't be modified. char* const is a constant pointer to a char, meaning the char can be modified, but the pointer can not (e.g. you can't make it point somewhere else).


1 Answers

The reason you've "never seen this before" is because this is using the syntax of the original, historical, K&R C version. That must be some real, old C code you're looking at. I just looked up, and ANSI C (C90) came out in 1990, so this code must be at least 30 years, or so, old.

I suppose this is something that needs to be known if one needs to deal with historic C code, but otherwise you can simply forget it.

The (void) cast means the same thing it means today.

like image 130
Sam Varshavchik Avatar answered Oct 30 '22 14:10

Sam Varshavchik