Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #387917
| Path | csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: is it possible to point to a slice of an array without malloc or VLAs? |
| Date | Wed, 28 Aug 2024 08:33:32 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 30 |
| Message-ID | <86ed68zmpf.fsf@linuxsc.com> (permalink) |
| References | <NS2dnaQtUKseUVP7nZ2dnZfqn_WdnZ2d@brightview.co.uk> <pan$97210$7f2c1504$c93772a0$7dfab761@invalid.invalid> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Date | Wed, 28 Aug 2024 17:33:33 +0200 (CEST) |
| Injection-Info | dont-email.me; posting-host="6b5ad5f5888a1a6f98ce057847c0415f"; logging-data="3703286"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AlizFEjZv/jjylsypQrilENx2QjU++Jw=" |
| User-Agent | Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) |
| Cancel-Lock | sha1:0k0gDrsjfOYteVtuaubF3sQy6Uw= sha1:PRl41N/FB/fXwbD5i1nDNFz5aQc= |
| Xref | csiph.com comp.lang.c:387917 |
Show key headers only | View raw
Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> writes:
> Mark Summerfield wrote:
>
>> I'm using getopt_long() to process a command line.
>> So after a typical call I might have:
>>
>> argv == {"./efind", "-D", "-x", "one", "two", "three", "four"}
>> optind == 3
>>
>> What I'd like to do (without copying or mallocing and without
>> using a VLA)
>> is to get a pointer to a slice of argv, specifically,
>> {"one", "two", "three", "four"}.
>> In Python terms argv[optind:argc].
>>
>> Is this possible in C?
>
> Yes.
>
> const char * argv_slice[argc - optind] = &argv[optind];
Presumably the declaration that was intended is something more
like
const char *(*argv_slice)[argc - optind] = (void*) &argv[optind];
It should be noted that this solution satisfies the stated
requirement of not using a VLA, but it does rely on using
a variably modified type.
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar
is it possible to point to a slice of an array without malloc or VLAs? Mark Summerfield <mark@qtrac.eu> - 2024-08-28 07:06 +0000
Re: is it possible to point to a slice of an array without malloc or VLAs? Phil Ashby <phil.eternal@ashbysoft.com> - 2024-08-28 09:13 +0100
Re: is it possible to point to a slice of an array without malloc or VLAs? Mark Summerfield <mark@qtrac.eu> - 2024-08-29 07:52 +0000
Re: is it possible to point to a slice of an array without malloc or VLAs? Ben Bacarisse <ben@bsb.me.uk> - 2024-08-29 11:04 +0100
Re: is it possible to point to a slice of an array without malloc or VLAs? Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-08-28 14:25 +0000
Re: is it possible to point to a slice of an array without malloc or VLAs? Ben Bacarisse <ben@bsb.me.uk> - 2024-08-28 16:29 +0100
Re: is it possible to point to a slice of an array without malloc or VLAs? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-28 08:33 -0700
csiph-web