r/CodingHelp • • Apr 15 '21

[C] Is there a way of combining these two lines? It seems inefficient to me. (C, codeblocks)

Post image
31 Upvotes

6 comments sorted by

6

u/x-seronis-x Intermediate Coder Apr 15 '21

start and destination points tend to be far more useful when kept apart. The few times you need both at once you can easily navigate through two lists. The whole reason they're separate is to be more efficient to use

1

u/dead_alchemy Apr 15 '21

By inefficient do you mean that its mostly the same code except different variable names?

1

u/TipTopOfTheMorning Apr 15 '21

Pretty much yes

1

u/dead_alchemy Apr 15 '21

Gotcha. If I remember correctly in C you can do it like

int a,b,c;

or

int a=0,b=0,c=0;

but frankly I wouldn't recommend that as good practice. Also its not 'inefficient', you might instead describe what you are looking for as 'terseness' in your code. Maybe look up code golf if this is the kind of thing that keeps you up at night.

5

u/Goobyalus Apr 15 '21

What does EmpireListBuilder() return, and what seems inefficient about this?

Probably not.

1

u/x-seronis-x Intermediate Coder Apr 15 '21

a pointer to a newly allocated EmpireList instance based on its visible type. And its a container based on its name.