Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #391868

Re: "array"

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: "array"
Date 2025-04-02 17:42 -0700
Organization A noiseless patient Spider
Message-ID <861puahy8h.fsf@linuxsc.com> (permalink)
References <array-20250402114422@ram.dialup.fu-berlin.de>

Show all headers | View raw


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).

Back to comp.lang.c | Previous | Next | Find similar


Thread

Re: "array" Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-04-02 17:42 -0700

csiph-web