Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <uvbg3i$sm6s$1@i2pn2.org>
Deutsch   English   Français   Italiano  
<uvbg3i$sm6s$1@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: fir <fir@grunge.pl>
Newsgroups: comp.lang.c
Subject: Re: improve that function (bytes_dig_int)
Date: Fri, 12 Apr 2024 16:22:41 +0200
Organization: i2pn2 (i2pn.org)
Message-ID: <uvbg3i$sm6s$1@i2pn2.org>
References: <uukcop$3vhcj$1@i2pn2.org> <86jzl72j9v.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 12 Apr 2024 14:22:43 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="940252"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
In-Reply-To: <86jzl72j9v.fsf@linuxsc.com>
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 3763
Lines: 81

Tim Rentsch wrote:
> fir <fir@grunge.pl> writes:
>
>> it seems that this group likes such kind of topics, so
>> here you got
>>
>> improve that function - i wrote it in quick and feel tired so i
>> dont want to improve it as for now
>>
>> i got "list" of bytes (by list i mean pointer to ram area of
>> elements - loke reallocked by reallock, by aray i would rather
>> aybe name fully static array and heap seeds are more like lists
>> especially if you use them as lists - and got methods like "add"
>> (remove etc)
>>
>>    unsigned char* bytes = NULL;
>>    int bytes_size = 0;
>>    int bytes_allocked = 0;
>>    int bytes_cursor = 0;
>>
>> i wint to write a function DigInt that "digs" one int form that
>> list and returns its, then the "cursor" is set after that and you
>> can call it again untill all ints are "digged"
>>
>> [code]
>
> I usually prefer (and recommend) writing code that doesn't make
> use of global state, as for example:
>
> long
> next_value( char *s0, char **next_s ){
>    char *s = s0 + strcspn( s0, "0123456789" );
>    return
>      !*s
>        ?   *next_s = s0,  0
>        :   strtol(  s - (s!=s0 && s[-1]=='-'),  next_s,  10  );
> }
>
> Retrieving and processing successive values can be done using
> this function by means of a simple for() loop, as illustrated by
> the code below:
>
> void
> print_longs( char *s ){
>    long v;
>
>    printf( " input:  %s\n", s );
>
>    for(  char *next;  v = next_value( s, &next ), s != next;  s = next  ){
>      printf( "   value:  %12ld\n", v );
>    }
>
>    printf( "\n" );
> }
>
> Note that the local variable 'next' here takes the place of a
> cursor for the next input.
>

well ok..this is kinda tricky style but thats a matter of personal style
i prefer more "strightforward" long descriptive names etc

two remarks here
1) people shoudl avoid imo talking a word "global" becouse in
normal desctop computing at least those variables are not global but
typically belong to library (dll) so they are library scope/module
scope not global (this is my own remark as i noticed this) (thay may 
also be exe scope but thsi is also module scope

so global dont much exist, though there is this problem that when same
symbol is uset in various libraries it may cause serious conflict

2) as to avaidingf global state i also thing would not agree

if the satae is "meaningfull" - like if variable name is really 
meanigfull for given module - it could be used (i mean it should
be as meaningful as functions provided, than can be "global" (module 
scoe) too imo by analogy

various "global" (id est module scope)  arrays for exampel are quite 
meaningfull so no problem them being module scope (and dont listen
to c++ ponys what they say imo, fuck them - in short - i would say ;c)