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 : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.c
Date : 28. Aug 2024, 11:50:54
Autres entêtes
Organisation : Stefan Ram
Message-ID : <slice-20240828104917@ram.dialup.fu-berlin.de>
References : 1
Mark Summerfield <mark@qtrac.eu> wrote or quoted:
argv == {"./efind", "-D", "-x", "one", "two", "three", "four"}
. . .
In Python terms argv[optind:argc].

#include <stdio.h>

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



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