Use of an undefined structure: TMatch.

Just starting out? Need help? Post your questions and find answers here.
ricardo_sdl
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Sep 21, 2019 4:24 pm

Use of an undefined structure: TMatch.

Post by ricardo_sdl »

I got this error message from the compiler: "Use of an undefined structure: TMatch."
The code is something like this:

Code: Select all

Structure TBattleTarget
	;bunch of stuff
	*Match.TMach
EndStructure
The structure definition compiles fine. But then I added this line inside a procedure:

Code: Select all

Debug *BattleTarget\Match\SomeUnitIsExecutingSkill
And got the error message. Why is this happening? My guess is that the compiler doesn't really know what Match inside TBattleTarget is at that point.
You can check my games at:
https://ricardo-sdl.itch.io/
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Use of an undefined structure: TMatch.

Post by Fred »

Is TMatch declared before the use ?
ricardo_sdl
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Sep 21, 2019 4:24 pm

Re: Use of an undefined structure: TMatch.

Post by ricardo_sdl »

Yes. The structures are declared on top of each file in this order:
Main.pb -> GameState.pbi -> Match.pbi -> Player.pbi -> BattleTarget.pbi -> Match.pbi
Eacho file is included with XIncludeFile.
You can check my games at:
https://ricardo-sdl.itch.io/
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: Use of an undefined structure: TMatch.

Post by Axolotl »

Maybe the typo is only in the shown code?

Code: Select all

Structure TBattleTarget
	;bunch of stuff
	*Match.TMach   ; <=== TMach or TMatch <=> That is the question
EndStructure
BTW: I always use this syntax for my user defined structures, and never got any problems.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
ricardo_sdl
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Sep 21, 2019 4:24 pm

Re: Use of an undefined structure: TMatch.

Post by ricardo_sdl »

Axolotl wrote: Wed Apr 16, 2025 3:34 pm Maybe the typo is only in the shown code?

Code: Select all

Structure TBattleTarget
	;bunch of stuff
	*Match.TMach   ; <=== TMach or TMatch <=> That is the question
EndStructure
BTW: I always use this syntax for my user defined structures, and never got any problems.
Indeed there is a typo on the example code. I verified my source code and the declaration *Match.TMatch has the same structure name as the declaration "Structure TMatch" inside Match.pbi, the autocomplete even shows the fields for the *Match member.
You can check my games at:
https://ricardo-sdl.itch.io/
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: Use of an undefined structure: TMatch.

Post by Axolotl »

well, without running code, it is difficult to make any suggestions.
So here are just a few thoughts:
In this case, do not rely on autocomplete. This is because autocompletion works with any open files.
I guess the compiler message indicates that the declaration is missing, or perhaps you have used the definition before the declaration?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Use of an undefined structure: TMatch.

Post by #NULL »

The definition of structure TBattleTarget will compile just fine, even if TMach (or TMatch) isn't defined because the field is a pointer, so purebasic doesn't really care at that point what TMach is. But when you start to work with it and its fields like in the Debug code, then purebasic needs to know and complains about it not being defined. You need to inspect your include chain to see how you end up without TMach at that point. Do some files include each other or something like that? Maybe placing different CompilerWarning messages before and after include statements can help if you can't figure it out by just looking at your files.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Use of an undefined structure: TMatch.

Post by #NULL »

ricardo_sdl wrote: Wed Apr 16, 2025 2:35 pmBut then I added this line inside a procedure:
Where did you add it?
If Match.pbi first includes Player.pbi before doing any declarations, then Player.pbi won't have those declarations from Match.pbi available. Same for BattleTarget.pbi, because even though is has its own inclusion of Match.pbi, that won't be done because XInclude (include only once) has already been started for that file in GameState.pbi, if I understand your outline correctly.
ricardo_sdl
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Sep 21, 2019 4:24 pm

Re: Use of an undefined structure: TMatch.

Post by ricardo_sdl »

#NULL wrote: Wed Apr 16, 2025 5:52 pm The definition of structure TBattleTarget will compile just fine, even if TMach (or TMatch) isn't defined because the field is a pointer, so purebasic doesn't really care at that point what TMach is. But when you start to work with it and its fields like in the Debug code, then purebasic needs to know and complains about it not being defined. You need to inspect your include chain to see how you end up without TMach at that point. Do some files include each other or something like that? Maybe placing different CompilerWarning messages before and after include statements can help if you can't figure it out by just looking at your files.
I didn't know the compiler wouldn't verify the type of the pointer declaration inside the structure! So it's probably that, since I have a circular dependency here leading to a "who came first? the chicken or the egg?" problem. I think one way to avoid that is spliting the declarations and definitions in two files like in C language with its .h and .c files.

Thank you all! I solved my problem for now using a procedure that returns the value I want. I'll try to structure my includes in a better way in future projects.
You can check my games at:
https://ricardo-sdl.itch.io/
Post Reply