Pass on function arguments by pointer

c, c++

Solution

No, this is neither portable nor well-defined. Compilers are not required to allocate function parameters in adjacent locations in memory. In fact, they are not required to place parameters `b` and `c` in memory at all, since you are not taking their address. Any access beyond the bounds of the `int` through `p` in `foo` is undefined behavior.

Problem

When function arguments are of the same type, is following code well-defined and portable? ``` void foo(int* p, int size); void pass_on_args_by_pointer(int a, int b, int c) { foo(&a, 3); } ``` To clearify: the 'size' argument should contain the number of elements in the array p. So, I want to pass all three ints to foo.

Original source