Path: ...!local-2.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Wed, 28 Aug 2024 07:06:43 +0000 From: Mark Summerfield Subject: is it possible to point to a slice of an array without malloc or VLAs? Newsgroups: comp.lang.c MIME-Version: 1.0 User-Agent: Pan/0.154 (Izium; 517acf4) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-ID: Date: Wed, 28 Aug 2024 07:06:43 +0000 Lines: 20 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-jhKxidspnU+xz7hR16yg3wgMDmiCqAFtvuadqKsf6WT/m5qBUmxHk9nM4PolMjLWSE8JyVWTAXn9Y/s!/NxHUsOyjiqh23htt6X5ywtA+r/x6o4KViu6Du47kpVXFlXb8b0AdLgvaf0dJpZPNwHas1p/2Lgp!Xt5Gq+9f9zolIxLqgrj9RcY+Qw== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Bytes: 1658 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? At the moment I store argv, optind, and argc and handle the slice using a loop: if (config->optind < config->argc) for (int i = config->optind; i < config.argc; ++i) process(config->argv[i]); This works fine, so really I'm just wondering if there's a nicer way.