Sujet : Re: "array"
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 03. Apr 2025, 01:42:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <861puahy8h.fsf@linuxsc.com>
References : 1
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
ram@zedat.fu-berlin.de (Stefan Ram) writes:
Below, an array is allocated dynamically.
>
#include <stdio.h>
#include <stdlib.h>
>
int main( void )
{ char *array_pointer = malloc( 10 * sizeof *array_pointer );
if( !array_pointer )return EXIT_FAILURE;
*array_pointer = 'a';
free( array_pointer ); }
>
But is it really an array according to the C spec?
>
C only defines "array type", not array, but it uses ISO/IEC 2382:2015
as a normative reference, and ISO/IEC 2382:2015 says:
>
|array
|An aggregate that is an instance of an array type and each
|element or appropriate group of elements in which may be
|referenced randomly and independently of the others.
ISO/IEC 2382-15 (1998), 15.03.08 (Can't access newer versions!)
>
. That block of memory that malloc allocated, does it have an
array type? I'm not sure. So are we allowed to call it an array?
I'm not sure why you are having trouble answering this question.
Did you read the section in the C standard for malloc(), and also
its parent section, "Memory management functions", that applies to
all the memory allocation functions (calloc(), malloc(), realloc(),
etc).