Path: ...!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.c Subject: Re: is it possible to point to a slice of an array without malloc or VLAs? Date: 28 Aug 2024 09:50:54 GMT Organization: Stefan Ram Lines: 30 Expires: 1 Jul 2025 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de MOFmmYFY1DmEfx401BM8GQlYVtAwe3UElfUpfst6IvCoSe Cancel-Lock: sha1:7lgLpepZg/knH/2R+Z8FZ4MqRxc= sha256:/MFBitb3609Zttd3hyiShH8aZnjFpaR5J4AUxyq85Y8= X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 2437 Mark Summerfield wrote or quoted: >argv == {"./efind", "-D", "-x", "one", "two", "three", "four"} .. . . >In Python terms argv[optind:argc]. #include int main() { char const * const argv[] = { "./efind", "-D", "-x", "one", "two", "three", "four" }; size_t const argc = sizeof( argv )/ sizeof( 0[ argv ]); printf( "%zu\n", argc ); char const * const * rest = argv + 3; /* <<< answer to the question */ for( char const * const * entry = rest; entry < argv + argc; entry++ ) printf( "%.32s\n", *entry ); } If that's not your jam, you can pretty much 86 all the "const" declarations in the program above. But if you're rolling in from Python, where "const" is ghost, it's hella tight to be able to use "const" again. You'd be missing out on the gnarliest feature in C! In Python, slices are always copied. Here in the C program above, the "slice" shares memory with the base array. (There's no such thing as "slices" in C.)