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

Pages: 1-

C++ bullshit

Name: Anonymous 2012-09-27 16:14

I have nested for loops, where I'm going over an array.
#define ARRAYSIZE 10


        for(drawx = 1; drawx<(ARRAYSIZE - 1); ++drawx)

is the first for

        for(drawy = 1; drawy<(ARRAYSIZE - 1); ++drawy)

is inside the first for's block.

Now for some reason, the x loop properly terminates at the final value of 9, while the y loop terminates at the value of 10. I.e. x completes 1-8, eight steps, while y does 1-9, nine steps. I could dump the whole shit into pastebin if anyone wants me to do that.

Name: Anonymous 2012-09-27 16:16

They both end at 10, but inside the scope you only see until 9, outside scope (after) you see them at 10 since the drawy symbol is defined in a more global scope.

Name: Anonymous 2012-09-27 16:19

>>2
Well they both should be ending at 9, since the whole (10-1) bit thing is part of the condition.

What do you mean by "more global"? I put int x; and int y; before the x loop.

Name: Anonymous 2012-09-27 16:24

hum you're right, maybe your code is changing their values mid-cycle, post a little code

Name: Anonymous 2012-09-27 16:28


        for(drawx = 1; drawx<(ARRAYSIZE - 1); ++drawx)
            {
                for(drawy = 1; drawy<(ARRAYSIZE - 1); ++drawy)
               {
                    if(myarray2[drawx][drawy])
                        {
                        //draws columns down first
                        driver->draw2DRectangle(video::SColor(255,255,255,255),
                                                       core::rect<s32>(gridstartx + (gridstarty * (drawx-1)),gridstarty * drawy,(drawx * gridstarty +gridstartx),(drawy+2) * gridstarty));
                        }
                    else
                        {
                        driver->draw2DRectangle(video::SColor(255,0,0,0),
                                                       core::rect<s32>(gridstartx + (gridstarty * (drawx-1)),gridstarty * drawy,(drawx * gridstarty +gridstartx),(drawy+2) * gridstarty));
                        }
                }
            }


The draw code is a bit of a clusterfuck, I do have a mistake or two in there (I'm trying to center a square grid), but otherwise, the for loop is pissing me right the fuck off.

http://tinypic.com/r/httkz8/6

That's how it looks, 8 squares wide, 9 squares tall.

Name: Anonymous 2012-09-27 16:32

that is indeed weird...

Name: Anonymous 2012-09-27 16:33

show the rest of the code

Name: Anonymous 2012-09-27 16:35

Is there any reason you're starting at 1 instead of 0?

Name: Anonymous 2012-09-27 17:04

>>8
and why ++var ?

Name: Anonymous 2012-09-27 17:25

>>9
That's just stylisting in this situation.

Name: Anonymous 2012-09-27 17:26

>>9
That's just stylistic in this situation.

Name: Anonymous 2012-09-27 17:58

>>8
I'm only using the inner section of an array, omitting the bordering elements because I don't want to have to deal with them.

http://pastebin.com/wYPUiNA6

This is compiled against the trunk branch of Irrlicht's SVN, should be fine using the 1.7.3 dll.

Name: Anonymous 2012-09-27 18:14

Son of a bitch, the drawing loop was messed up. I'm retarded, I was drawing the squares 2 in height, which ended up making everything twice as long, which manifested as the last squares being twice as long vertically but the rest of the grid looking fine.

Name: Anonymous 2012-09-27 18:33

for(y=0; y < ARRAYSIZE;++y )
for (y = 0; y < ARRAYSIZE; ++y) next time kudasai

Name: Anonymous 2012-09-27 21:49

>>14
>premature optimizations

Name: Anonymous 2012-09-27 22:09

>>15
What are you talking about? It's simple styling.

/polecat kegabs/

Name: Anonymous 2012-09-27 22:17

>>16
Except ++y is different to y++, particularly in the case of loops. Every textbook tries to make this point very clear, so I don't see why you don't seem to realise it.

Name: Anonymous 2012-09-27 22:23

>>17
Because I just kopipe'd his code and did some style modifications.

I didn't bother reading such an ugly piece of shit; I'm not sure if the pre-increment operator is vital or not for his code and I don't care because his style is shit.

Name: Anonymous 2012-09-27 23:30

>>16
Style is optimizing, as standardized styling implies readability.

Name: Anonymous 2012-09-27 23:49

>>19
not >>18. but how is

for(int a=1; a< 5; a++ ){
         ^     ^      ^
[code]
more readable than
[code]
for (int a = 1; a < 5; a++) {

?

Name: Anonymous 2012-09-28 1:16

>>1
#define ARRAYSIZE 10
#define NELEM(arr) (sizeof(arr) / sizeof(*(arr)))

Name: Anonymous 2012-09-28 1:36

Name: Anonymous 2012-09-28 10:05

>>21
char *troll = malloc(9000);
printf("%ld\n", NELEM(troll));

Name: Anonymous 2012-09-28 17:23

>>17
Amateur-level trolling, as individual statements both forms will produce the same code, unless your compiler is more than 20 years old.

Don't change these.
Name: Email:
Entire Thread Thread List