Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are the elements of the argv array always contiguous in memory?

Tags:

c

unix

posix

On Linux, the elements of the argv array always seem to occupy contiguous positions in memory, i.e. the first character of argv[n+1] immediately follows the terminating nul byte of argv[n], for n = 0...(argc-1).

Is this guaranteed to be the case on all POSIX systems/all C implementations?

like image 608
nswered Avatar asked Jul 15 '14 18:07

nswered


People also ask

Is an array contiguous memory?

An array is a contiguous collection of homogeneous elements that can be accessed using an index. By contiguous, we mean the elements of the array are adjacent to one another in memory with no gaps between them.

Are arrays of structs contiguous?

Structure arrays do not require completely contiguous memory. However, each field requires contiguous memory, as does the header that MATLAB® creates to describe the array. For very large arrays, incrementally increasing the number of fields or the number of elements in a field results in Out of Memory errors.

What is the data type of the elements of argv?

argv is of type char ** . It is not an array. It is a pointer to pointer to char . Command line arguments are stored in the memory and the address of each of the memory location is stored in an array.

What kind of array is argv?

The second parameter, argv (argument vector), is an array of pointers to arrays of character objects. The array objects are null-terminated strings, representing the arguments that were entered on the command line when the program was started.


1 Answers

This is not guaranteed. Neither by C, neither by POSIX.

like image 81
ouah Avatar answered Oct 18 '22 20:10

ouah