Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Input

Name: Anonymous 2009-03-31 13:05

I've got two methods of initializing large quantities of variables. Which piece of code should be used? Not only performance wise but also for readability.


void menu_draw_init(){
    path_buffer =  malloc(MENU_PATH_COUNT);
    u8 c;

    for(c=0;c<MENU_PATH_COUNT;c++)
        if(c)
            path_buffer[c] = &buffer_sub;
        else
            path_buffer[c] = &buffer_main;
}

--OR--


void menu_draw_init(){
    path_buffer =  malloc(MENU_PATH_COUNT);

    path_buffer[0] = &buffer_main;
    path_buffer[1] = &buffer_sub;
    path_buffer[2] = &buffer_sub;
    path_buffer[3] = &buffer_sub;
            ...
    path_buffer[81] = &buffer_sub;

}

So which piece of code is better to use?

Name: Anonymous 2009-03-31 13:07

The first with loop unrolling. Idiot.

Name: Anonymous 2009-03-31 13:09

path_buffa[0] = &buffa_main;
for (c = 0; c < MENU_PATH_CUNT; ++c) path_buffa[c] = &buffa_sub;


I hope everyone you love dies painfully.

Name: Anonymous 2009-03-31 13:10

>>3
c = 1, rather. That's how angry you've made me.

Name: Anonymous 2009-03-31 13:11

>>2
No need for the insult... I only started programing recently. Oh and thanks I learn't a new concept.

Name: Anonymous 2009-03-31 13:14

>>3
That was just an example. How about when I want to use a less than statement*

Name: Anonymous 2009-03-31 13:17

>>5
Stop programming forever. Fucknut.

Name: Anonymous 2009-03-31 13:25

ghci> let path_buffer = buffer_main : (replicate 81 buffer_sub)

Name: Anonymous 2011-02-04 12:40

Name: Anonymous 2011-02-17 20:26

check 'em dubzNewer Posts
Don't change these.
Name: Email:
Entire Thread Thread List