0

help

const char *const argv[] = {"aaa", "bbb", "ccc"}; after it this come: func( (char *const *) argv ); what is mean I saw someone who did it

7th Jun 2024, 1:50 PM
Jables
Jables - avatar
6 Respostas
+ 3
you asking what means the `const char* const` on the array? It means array contains constant pointers to constant characters. This ensure that neither the pointers of the text can changed, neither can modify the characters in the texts
7th Jun 2024, 1:59 PM
john ds
john ds - avatar
+ 1
You not need this typecast at all. I assume the function gets a `char* const*` argument so it's same type as the array. If it gives compile error without it and function gets this type, then maybe is for compiler compatibility reasons
7th Jun 2024, 3:40 PM
john ds
john ds - avatar
+ 1
Jables the function takes 2 arguments, i believe you want pass the array to the 2nd argument. Doing this typecast here it keep the constant for the pointers but you can now edit the characters of the texts inside the function. When you have any constant variable, you can bypass this 'lock' and actually edit its data by using typecasts, but you should never do it even if language allow it. Its very bad practice. Now if this cause issues or not, it depends on what the execvp does internally but probably it will cause problems, otherwise will had asked for a constant argument
7th Jun 2024, 11:37 PM
john ds
john ds - avatar
0
OK I got it what's about the next line the typecast why he did it
7th Jun 2024, 2:02 PM
Jables
Jables - avatar
0
what's the typecast mean ?
7th Jun 2024, 2:23 PM
Jables
Jables - avatar
0
the function it's 'execvp' int execvp(const char *file, char *const argv[]); by does (char *const *)argv it's mean he cast to immutable pointer to mutable char ? can you explain it to me pls?
7th Jun 2024, 3:56 PM
Jables
Jables - avatar