Re: is it possible to point to a slice of an array without malloc or VLAs?

Liste des GroupesRevenir à l c 
Sujet : Re: is it possible to point to a slice of an array without malloc or VLAs?
De : mark (at) *nospam* qtrac.eu (Mark Summerfield)
Groupes : comp.lang.c
Date : 29. Aug 2024, 09:52:02
Autres entêtes
Message-ID : <4Z6dnTcuH5c_tU37nZ2dnZfqn_qlxKTP@brightview.co.uk>
References : 1 2
User-Agent : Pan/0.154 (Izium; 517acf4)
On Wed, 28 Aug 2024 09:13:39 +0100, Phil Ashby wrote:
[snip]
To answer the specific question, I would use pointer arithmetic,
provided there is no intention to modify values, ie:
 
char **slice = argv + config->optind;
 
thus slice now points at the appropriate part of argv and can be indexed
or dereferenced / incremented to access elements.
[snip]

Thank you, that works great. I now do that plus store the slice's size using:
argc - optind

I tried to get the size using

#define ARRAYSIZE(a) (&(a)[1] - (a))

char **folders = argv + optind;
int num_folders = argc - optind;
int size = ARRAYSIZE(folders);
printf("%d %d\n", num_folders, size);

but size was always 1.

Date Sujet#  Auteur
28 Aug 24 * is it possible to point to a slice of an array without malloc or VLAs?8Mark Summerfield
28 Aug 24 +* Re: is it possible to point to a slice of an array without malloc or VLAs?3Phil Ashby
29 Aug 24 i`* Re: is it possible to point to a slice of an array without malloc or VLAs?2Mark Summerfield
29 Aug 24 i `- Re: is it possible to point to a slice of an array without malloc or VLAs?1Ben Bacarisse
28 Aug 24 +- Re: is it possible to point to a slice of an array without malloc or VLAs?1Stefan Ram
28 Aug 24 `* Re: is it possible to point to a slice of an array without malloc or VLAs?3Blue-Maned_Hawk
28 Aug 24  +- Re: is it possible to point to a slice of an array without malloc or VLAs?1Ben Bacarisse
28 Aug 24  `- Re: is it possible to point to a slice of an array without malloc or VLAs?1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal