I get some errors.. if anyone could help me "C"

I have follow some videos on youtube like to make a game in C from scratch.. all fine until I get this error:


game.c|2|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'|
math.c|2|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'|


.. and these are the files I have until now:


Win32_platform.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "utils.c"
#include "math.c"
#include "platform_common.c"

#include <windows.h>

struct
{
    // Platform non-specific part
    int width, height;
    u32 *pixels;

    // Platform specific part
    BITMAPINFO bitmap_info;

}typedef Render_Buffer;


global_variable Render_Buffer render_buffer;


#include "software_rendering.c"
#include "game.c"

internal LRESULT
CALLBACK window_callback(HWND window, UINT message, WPARAM w_param, LPARAM l_param)
{
    LRESULT result = 0;

    switch(message)
    {
    case WM_CLOSE:
    case WM_DESTROY:
        {
            running = false;
        }break;

    case WM_SIZE:
        {
            // get width and height
            RECT rect;
            GetWindowRect(window, &rect);
            render_buffer.width = rect.right - rect.left;
            render_buffer.height = rect.bottom - rect.top;

            if(render_buffer.pixels)
            {
                //free buffer
                VirtualFree(render_buffer.pixels, 0, MEM_RELEASE);
            }

            // allocate the buffer
            render_buffer.pixels = VirtualAlloc(0, sizeof(u32)*render_buffer.width*render_buffer.height,
                                                MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);

            //fill the bitmap_info
            render_buffer.bitmap_info.bmiHeader.biSize = sizeof(render_buffer.bitmap_info.bmiHeader);
            render_buffer.bitmap_info.bmiHeader.biWidth = render_buffer.width;
            render_buffer.bitmap_info.bmiHeader.biHeight = render_buffer.height;
            render_buffer.bitmap_info.bmiHeader.biPlanes = 1;
            render_buffer.bitmap_info.bmiHeader.biBitCount = 32;
            render_buffer.bitmap_info.bmiHeader.biCompression = BI_RGB;
            render_buffer.bitmap_info.bmiHeader.biSizeImage = 0;
        }break;

    default:
        {
            result = DefWindowProcA(window, message, w_param, l_param);
        }
    }

    return result;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
    WNDCLASSA window_class = {0};

    window_class.style         = CS_HREDRAW | CS_VREDRAW;
    window_class.lpszClassName = "Game_Window_Class";
    window_class.lpfnWndProc   = window_callback;

    RegisterClassA(&window_class);

    HWND window = CreateWindowExA(0, window_class.lpszClassName, "PusPus",
                                  WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
                                  CW_USEDEFAULT, 1366, 768, 0, 0, 0, 0);

    HDC hdc = GetDC(window);

    Input input = {0};

    while(running)
    {
        //Input
        MSG message;
        while(PeekMessageA(&message, window, 0, 0, PM_REMOVE))
        {
            switch(message.message)
            {
            case WM_SYSKEYDOWN:
            case WM_SYSKEYUP:
            case WM_KEYDOWN:
            case WM_KEYUP:
                {
                    u32 vk_code = (u32)message.wParam;
                    b32 was_dowm = ((message.lParam & (1 << 30)) != 0);
                    b32 is_down = ((message.lParam & (1 << 31)) == 0);

                    if(vk_code == VK_LEFT)
                        input.buttons[BUTTON_LEFT].is_down = is_down;
                        input.buttons[BUTTON_LEFT].changed = true;
                }break;

            default:
                {
                    TranslateMessage(&message);
                    DispatchMessage(&message);
                }
            }
        }

        //Simulation
        simulate_game(&input);

        //Render
        StretchDIBits(hdc, 0, 0, render_buffer.width, render_buffer.height, 0, 0, render_buffer.width,
                      render_buffer.height, render_buffer.pixels, &render_buffer.bitmap_info , DIB_RGB_COLORS, SRCCOPY);

    }

    return (0);
}



utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdint.h>

typedef int8_t s8;
typedef uint8_t u8;

typedef int16_t s16;
typedef uint16_t u16;

typedef int32_t s32;
typedef uint32_t u32;

typedef int64_t s64;
typedef uint64_t u64;

typedef int b32;

#define true 1
#define false 0

#define global_variable static
#define internal static

global_variable b32 running = true;



software_rendering.c
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
internal void
clear_screen(u32 color)
{
    u32 *pixel = render_buffer.pixels;

    for(int y = 0; y < render_buffer.height; y++)
    {
        for(int x = 0; x < render_buffer.width; x++)
        {
            *pixel++ = color;
        }
    }
}

internal void
draw_rect_in_pixels(int x0, int y0, int x1, int y1, u32 color)
{
    x0 = clamp(0, x0, render_buffer.width);
    x1 = clamp(0, x1, render_buffer.width);
    y0 = clamp(0, y0, render_buffer.height);
    y1 = clamp(0, y1, render_buffer.height);

    for(int y = y0; y < y1; y++)
    {
        u32 *pixel = render_buffer.pixels + x0 + render_buffer.width*y;
        for(int x = x0; x < x1; x++)
        {
            *pixel++ = color;
        }
    }
}



math.c
1
2
3
4
5
6
7
internal int
clamp(int min, int val, int max)
{
    if(val < min) return min;
    if(val > max) return max;
    return val;
}



game.c
1
2
3
4
5
6
7
internal void
simulate_game(Input *input)
{
    clear_screen(0x444f0f);
    if(input->buttons[BUTTON_LEFT].is_down)
        draw_rect_in_pixels(100, 100, 200, 200, 0xffff00);
}



platform_common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
struct
{
    b32 is_down;
    b32 changed;
} typedef Button;

enum
{
    BUTTON_LEFT;
    BUTTON_RIGHT;
    BUTTON_UP;
    BUTTON_DOWN;

    BUTTON_COUNT;
};

struct
{
    int mouse_x;
    int mouse_y;

    Button buttons[BUTTON_COUNT];

} typedef Input;


I just don't know what these error refers to.. ??
I don't think the keyword internal is being used correctly or if that's even a thing in c++ or c. Id delete that and go from there.
Well.. here is the link from where I have try to do so... I believe Internal is C as how is explaining it. https://www.youtube.com/watch?v=cTwh9oHcs1w

But hey.. thank you for your answer I'll try to do it without using Internal.
BTW.. I'm not using Visual studio with 4Coder the way he is doing , just CodeBlocks if this is a problem to my errors.
I do not know much about codeblocks but windows.h and some of the other GUI stuff may be giving you trouble; its not standard c/c++ its microsoft gui libraries eg hwnd
Yeahh.. still without looking if it's C or GUI stuff or whatever.. what this :


game.c|2|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'|
math.c|2|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'|


even mean... ? I tried to remove Internal in front of the void type and I remain with one error from math.c that is still the same error, and removing even that , I now have other errors, like undefined reference.. or something to some arguments u32, etc..
Also note that #including source files will probably cause problems. Source files usually should be added to the project, not #included.

Also you are using archaic syntax for your structure definitions. Modern C use something more like:

1
2
3
4
5
6
7
typedef struct Render_Buffer
{
    // Platform non-specific part
    int width, height;

}Render_Buffer;
 


Your use of "internal" should probably be "static" which means that the functions would only be visible in the current compilation unit.



it means what it says. It ran into something it did not expect, and gave a list of possible things it thought it should see next. C and c++ errors and warnings take some practice to read, but once you kind of get it, they start making more sense and why they are like they are follows. There is a lot of madness in the method, but its reasonably consistent across compilers most of the time if nothing else. The good news is you can double click it to see where it is mad (or you have the line number too) and even better the error code has a 'why this' online page .. do a web search on the error code eg c12345 type number.

here, it is unhappy with 'internal' and can't make sense of what to do.

it is also screwy to include c files instead of h files. Its legal, but unwise outside of a few very specific cases (you can use it to force inline stubborn functions, for one, something not used much anymore because compilers do a better job at inline now).

Last edited on
I'm just saying Google "keyword internal c" and see what comes up... nothing significant. I've fought my way 3/4 of the way through the c practice section on hackerrank and I have not seen that. I'm assuming that the author has it typedefed to something else.

Now I see it. Utils.c you have #define internal static

That definition doesn't seem to be permeating through the entire program. Try including utils.c in the files that are complaining.


Or just use static as was said
Last edited on

Hey.. thanks guys, I've learned a lot today. I made a lot of changes but nothing, I'll just start over with a fresh project and try to do as jonnin says. Still I keep wonder why someone that has a good knowledge about programing, post it on youtube even legal includes .c files instead of .h and why this ancient method.. I though with my skills I can do that, but seems not. At a point I just copy and paste.. and in the end the game even works for him, and I'm at the first episode and so much errors.
However programing is not for everyone and that's a sure thing. Once again I apologies for bother you every time with my stupid codes, I don't have any friends programmers and here is the only way I get some good answers and sorry for steal your time. Next time I'll ask something else that worth and has some logic.
Again, including C files is legal, its just a bit unusual. If the guy knows how to make it work, it will work. It just creates problems, esp for beginners or for very large projects.

And do come to ask questions. Everyone was a beginner once. I know not to include C files... because I used to do it, and made a mess a couple of times. It was easier/faster for school type programs, but no good for larger stuff.

As for the video... another example... for decades, a well known book in C filled with bad practices and raw hacks was touted by experts as the book to have, can't live without it, blah blah. That thing is still available, I think (to be fair I think they finally cleaned it up). It was written by non programmers for non programmers, and the code works, but it (was) just pure awful. Anyone can claim to have the answer and be an expert, and some even get rich doing so. Buyer beware etc.
Last edited on
Thank you jonnin and not only.. But as you said it's bad to include .c files, I thought it's working just like including headers... but seems like what you said is true, is a bit unusual. And I just create a new project and instead of source files I pass all to headers, and now working just fine. 0[ZERO] ERRORS :). As another solution was to put all the definition in one source file (main.c), without making all this mess, would work the same 100%.
I could continue with this just to see this project or whatever game is working, but I need to lay down and read basic things, combining the C with GUI windows stuff, cool things can be created , but passing from a beginner in C to GUI could discourage many people to continue learning the way should be.. Thank you guys again. I'll try to put my mind to work next time before ask something that I don;t have knowledge.. Cheers ! :)
the general idea is to organize stuff by what it does, into one h file and one c file. As much as possible, stand alone so you can reuse little pieces -- the linked list you wrote, the file reader you wrote, all that may be useful again someday but if its all intertwined it won't be.
all in one file is fine for fairly small projects, though.
Hey I ain't mad at ya. Ask away no question is too simple if you're at least trying. I'd think it more counterintuitive to not ask.

I will definitely say a ground up approach to learning is the best way. Skipping over the basics just leads to endless frustration. It's like trying to build a house of cards but you're missing the cards for the bottom. It can be done but definitely the harder path.

The lesson here is don't use define on pointless feel good stuff that doesn't serve a purpose. With defines, typedefs and templates you can create code that is virtually unreadable to anyone who isn't the author. Even then you'll forget half of the nonsense and have to spend time relearning your old style. Just ridiculous.

The only other thing I can say about the posted code, don't ask me why but I learned awhile back that if you're going to include windows.h to include it first b4 anything else. I've had issues in the past where simply doing that cured all my problems.
Topic archived. No new replies allowed.