Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c,comp.programming,comp.sys.raspberry-pi Subject: Re: C is not a low level language Followup-To: comp.lang.c Date: Mon, 25 Feb 2019 13:36:02 -0800 Organization: None to speak of Lines: 32 Message-ID: References: <20190225122040.a476b092a257d6c0a3100deb@eircom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="d7a76040ef7e877133de8f8312ada9dc"; logging-data="32718"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19v+Jsr89/fE7gLwhTRNOC0" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:vUBVdSVSalKcfG29MY9CItNKnZM= sha1:QShn1/OydkMDd5407iiXcql8rxM= Xref: csiph.com comp.lang.c:141359 comp.programming:9745 comp.sys.raspberry-pi:19751 Ahem A Rivet's Shot writes: [...] > For a more dramatic example of efficiency consider strtok(), the > routine at the heart of turning a string into argc and argv. It works by > injecting nulls into the string where the spaces are and returning an array > of pointers to the starts of the words in the original string - In other > words it turns a single string into several strings and returns them in an > array - and it does so in place without using more memory than is > absolutely essential. Doing string manipulation in place with minimal > overhead was very important at the time C was designed. Quibble: No, strtok() doesn't return an array of pointers (for the simple reason that a C function cannot return an array value). It returns a single string pointer on each call. You have to call it multiple times to get pointers to all the tokens. It uses its own static memory to keep track. Incidentally, I don't believe strtok is used to turn a string into argc and argv. That's handled by the shell, and tokenizing on white space doesn't work. For example: echo arg1 'arg 2' passes two arguments to echo, not three. (bash does use strtok in some places; I'm not sure just how it's used.) [followups to comp.lang.c] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */