fir
2024-03-28 13:40:36 UTC
you know famous fir list
fir list its a list container i somewhat "invented",
i write "invented" as its reasonably simple thing but i never heard
anyone uses it so as for me i invented it for personal use and use it
its list it is a resizable "array" that has a method to add new elemnt
to it -- i aslo vrite some othor method if need, depending on use case
here it is
struct Fir_List_Entry {int x, y;};
Fir_List_Entry* Fir_List = NULL;
int Fir_List_Size = 0;
void Fir_List_AddOne(Fir_List_Entry* entry)
{
Fir_List_Size++;
Fir_List = (Fir_List_Entry*) realloc(Fir_List, Fir_List_Size *
sizeof(Fir_List_Entry) );
Fir_List[Fir_List_Size-1] = *entry;
return ;
}
use it like that
void Test()
{
Fir_List_Entry f1 = {11,22};
Fir_List_Entry f2 = {33,44};
Fir_List_AddOne(&f1);
Fir_List_AddOne(&f2);
for(int i=0; i<Fir_List_Size; i++)
printf("%d %d", Fir_List[i].x, Fir_List[i].y);
}
some could usually wrote a more convenient Add "method" not to pass
structures but just arguments and struct assigment do inside
C sadly not support a things to it be look betetr and more convenient
- it simply should be buil in in c but is not
so out of suriosity is it possible to write a macro on this? thsi macro
should rename the "Fir" part and put given name magin GivenList not FirList
macros are unconveniant and i doont use it but just out of curiosity
fir list its a list container i somewhat "invented",
i write "invented" as its reasonably simple thing but i never heard
anyone uses it so as for me i invented it for personal use and use it
its list it is a resizable "array" that has a method to add new elemnt
to it -- i aslo vrite some othor method if need, depending on use case
here it is
struct Fir_List_Entry {int x, y;};
Fir_List_Entry* Fir_List = NULL;
int Fir_List_Size = 0;
void Fir_List_AddOne(Fir_List_Entry* entry)
{
Fir_List_Size++;
Fir_List = (Fir_List_Entry*) realloc(Fir_List, Fir_List_Size *
sizeof(Fir_List_Entry) );
Fir_List[Fir_List_Size-1] = *entry;
return ;
}
use it like that
void Test()
{
Fir_List_Entry f1 = {11,22};
Fir_List_Entry f2 = {33,44};
Fir_List_AddOne(&f1);
Fir_List_AddOne(&f2);
for(int i=0; i<Fir_List_Size; i++)
printf("%d %d", Fir_List[i].x, Fir_List[i].y);
}
some could usually wrote a more convenient Add "method" not to pass
structures but just arguments and struct assigment do inside
C sadly not support a things to it be look betetr and more convenient
- it simply should be buil in in c but is not
so out of suriosity is it possible to write a macro on this? thsi macro
should rename the "Fir" part and put given name magin GivenList not FirList
macros are unconveniant and i doont use it but just out of curiosity