Why are there these redefinition bugs?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
misterchi
Posts: 20
Joined: November 12th, 2016, 3:15 pm

Why are there these redefinition bugs?

Post by misterchi » February 25th, 2017, 10:41 pm

Hi everyone,

I'm programming a game myself with the skills I learnt from Chili.
But now, I have some annoying errors and I don't know how to deal with them. According to stackoverflow the erros occur because of some header-linking things.

Hope you can help me and thx in advance!

misterchi
Attachments
MyGame.zip
(22 Bytes) Downloaded 111 times

User avatar
SlevinKelevra
Posts: 80
Joined: September 9th, 2013, 12:58 am
Location: Germany

Re: Why are there these redefinition bugs?

Post by SlevinKelevra » February 25th, 2017, 11:01 pm

You zip file is empty...
Carpe noctem

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Why are there these redefinition bugs?

Post by MrGodin » February 25th, 2017, 11:07 pm

If you make a new header file and include say, Game.h in it, and include that new file in Game.h as well, you'll get errors., if thats the case.
Or maybe you are making a variable, say int x (or something) in UpdateModel() for instance, then make another variable int x somewhere else in UpdateModel(), that'll make errors as well.
Curiosity killed the cat, satisfaction brought him back

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Why are there these redefinition bugs?

Post by albinopapa » February 25th, 2017, 11:44 pm

If it's the macro redefinitions, _WINNT_WIN32, STRICT and so on, it's because of the way chili has setup the framework. He has a bunch of #defines in ChiliWin.h and any time you include say Graphics.h in another file, ChiliWin.h is included in the list of headers. So each time that file is included, it tries to redefine those macros. The other thing would be if you #include <Windows.h> as well, you'll get the same result.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Why are there these redefinition bugs?

Post by albinopapa » February 25th, 2017, 11:47 pm

Another reason for redefinition errors, it creating a variable or a function in the header file outside of a class. For functions that don't belong to a class, you have to use the inline keyword

Code: Select all

inline void Function(params)
{
     return;
}

If you are declaring a variable in the header outside of a class, then it must be static or extern.

Code: Select all

// SomeHeader.h
static int a;
extern int b;

// SomeSource.cpp
int a = 0;
int b = 0;
Another thing might be that you forgot to add #pragma once at the top of the header file.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Why are there these redefinition bugs?

Post by chili » February 26th, 2017, 5:27 am

There was a little problem with the framework. The way it is setup, "ChiliWin.h" should be included before any other windows headers. But in graphics.h I include the D3D header first, and that can cause problems. The fix is to include "ChiliWin.h" at the top of "Graphics.h"

I do this in the latest version of the framework on GitHub.
Chili

misterchi
Posts: 20
Joined: November 12th, 2016, 3:15 pm

Re: Why are there these redefinition bugs?

Post by misterchi » February 26th, 2017, 10:46 am

Ok, I found the bug. Now it's fixed. Thx

Post Reply