3

Can somebody explain what is actually defined in the following code, as well as what is const at the end? Is a variable named __user and a pointer __argv of type __user created?

const char __user *const __user *__argv

I am familiar with the possibilities of placing const (make pointer/data unmodifiable), but I've never thought of the above possibility.

The snippet is from this function declaration in the kernel:

1593 int do_execve(const char *filename,
1594         const char __user *const __user *__argv,
1595         const char __user *const __user *__envp,
1596         struct pt_regs *regs)

EDIT: I probably wouldn't have asked the question had I known about the __user macro before. Still, it's not exactly a duplicate of this because the actual type of defined variable is not discussed there.

Community
  • 1
  • 1
zbarni
  • 69
  • 4
  • 1
    I would assume `__user` is actually a macro of some kind. – Platinum Azure Jul 31 '15 at 17:20
  • 1
    possible duplicate of [What are the implications of the linux \_\_user macro?](http://stackoverflow.com/questions/4521551/what-are-the-implications-of-the-linux-user-macro) – Ryan Haining Jul 31 '15 at 17:21
  • 1
    If you're curious why it might use `const char *const *` instead of `const char **`, see [Why am I getting an error converting a Foo** → const Foo**?](https://isocpp.org/wiki/faq/const-correctness#constptrptr-conversion) in the C++ FAQ. Basically, converting from `Foo**` to `const Foo**` is unsafe and illegal, but `Foo**` to `const Foo* const*` is safe. – Lithis Jul 31 '15 at 17:41
  • Do not add tags at random. – too honest for this site Jul 31 '15 at 18:07

2 Answers2

5

Actually, __user is a macro providing some attributes (more on this here). So, the variable is named __argv, which is of type pointer to const pointer to const char.

Community
  • 1
  • 1
lisyarus
  • 15,025
  • 3
  • 43
  • 68
0

const T *p and T const *p declare p as a pointer to const T.

T * const p declares p as a const pointer to T.

const T * const p and T const * const p both declare p as a const pointer to const T.

John Bode
  • 119,563
  • 19
  • 122
  • 198