funny errors

hi guys i m having a weird problem

here is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
Uint32          rmask, gmask, bmask, amask;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif 


funnily it gives me error at lines 9 to 12. says
C:\Users\Ceset\Desktop\test5\main.cpp|20|error: 'rmask' does not name a type|
C:\Users\Ceset\Desktop\test5\main.cpp|21|error: 'gmask' does not name a type|
C:\Users\Ceset\Desktop\test5\main.cpp|22|error: 'bmask' does not name a type|
C:\Users\Ceset\Desktop\test5\main.cpp|23|error: 'amask' does not name a type|
||=== Build finished: 4 errors, 0 warnings (0 minutes, 0 seconds) ===|


why is this happening even though it doesnt gives error at 4 to 7. i dont understand. thx in advance
Last edited on
Where is this code? If it is not in a function then it is of course going to give that error.
here is the whole code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <string>

Uint32          rmask, gmask, bmask, amask;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

SDL_Window*     window      = NULL;
int             width       = 640,
                height      = 480,
                widthBD     = width,
                heightBD    = 48;
SDL_Surface*    border      = NULL;
SDL_Texture*    tex         = NULL;
SDL_Renderer*   renderer    = NULL;
SDL_Rect        rect;

int main ( int argc, char** argv )
{
    window = SDL_CreateWindow("My Own Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED
                              ,width ,height ,SDL_WINDOW_SHOWN|SDL_WINDOW_BORDERLESS);

    border = SDL_CreateRGBSurface(0, widthBD, heightBD, 32,
                                  rmask, gmask, bmask, amask);

    renderer = SDL_CreateRenderer(window, -1, 0);

    tex = SDL_CreateTextureFromSurface(renderer, border);

    rect.x = 0;
    rect.y = 0;
    rect.w = widthBD;
    rect.h = heightBD;

    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, tex, NULL, &rect);
    SDL_RenderPresent(renderer);

    SDL_Delay(2000);

    return 0;
}


EDIT:also just to try, i put the codes which gives error between /* */. and it worked fine ?!?

and i use C::B

when i used it as this it is still fine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
    {
        rmask = 0xff000000;
        gmask = 0x00ff0000;
        bmask = 0x0000ff00;
        amask = 0x000000ff;
    }
    else
    {
        rmask = 0x000000ff;
        gmask = 0x0000ff00;
        bmask = 0x00ff0000;
        amask = 0xff000000;
    }
Last edited on
Lines 15-23 count as statements, not as definitions, and statements are not allowed in the global scope.
wow, i will try to remember that. thx
Topic archived. No new replies allowed.