Sujet : Re: macro for fir list?
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.cDate : 28. Mar 2024, 18:17:47
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <uu48nm$3bgp1$1@i2pn2.org>
References : 1 2 3
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
fir wrote:
fir wrote:
(bump to see this thread on narkive to see it from phone, weird narkive
dont show threads with only 1 post)
>
there is hovever yet such weir option
>
its weird though convenient
>
struct Fir_List_Entry {int x, y;};
>
Fir_List_Entry* Fir_List = NULL;
int Fir_List_Size = 0;
>
Fir_List_Entry* Fir_List_New()
{
Fir_List = (Fir_List_Entry*) realloc(Fir_List, ++Fir_List_Size *
sizeof(Fir_List_Entry) );
return &Fir_List[Fir_List_Size-1];
}
>
>
void Test()
{
*(Fir_List_New()) = {1,2};
*(Fir_List_New()) = {3,4};
*(Fir_List_New()) = {5,6};
>
for(int i=0; i<Fir_List_Size; i++)
printf("\n %d %d", Fir_List[i].x, Fir_List[i].y);
}
>
>
handcrafted lists for int, chat* etc could also be written ...
here is soem for pack of str_list (fir str list), as you usually need more than one
i used resizable list of resizable lists and so on back teh *wrote on thsi here but this form with _New as above i noticed first time here
// sickle.h
struct str_list_entry { char* str;};
const int str_lists_max = 10;
str_list_entry* str_list[str_lists_max] = {NULL};
int str_list_size[str_lists_max] = {0};
str_list_entry* str_list_new(int N) {
str_list[N] = (str_list_entry*) realloc(str_list[N], ++str_list_size[N] * sizeof(str_list_entry) );
return &str_list[N][str_list_size[N]-1]; }
//main.c
#include "sickle.h"
void Test()
{
*str_list_new(0)={"ala"};
*str_list_new(0)={"ma"};
*str_list_new(0)={"kota"};
*str_list_new(1)={"starcrawler"};
*str_list_new(1)={"skating polly"};
*str_list_new(1)={"lil xan"};
*str_list_new(1)={"kenny mason"};
for(int i=0; i<str_list_size[0]; i++) printf("\n %s ", str_list[0][i].str);
for(int i=0; i<str_list_size[1]; i++) printf("\n %s ", str_list[1][i].str);
}