Structure - Already defined

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Structure - Already defined

Post by Perkin »

Could you alter the warning for Structures/Prototype/Interface, so if it's already defined, as long as it matches previous definition, it's ignored, rather than having the Warning.
(Same as you do with Constants)


I'm testing quite a few of old codes, and now a lot of structures etc are now defined natively.
If I use an older PB version, without the definitions they need to be included.
%101010 = $2A = 42
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Structure - Already defined

Post by ts-soft »

Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Structure - Already defined

Post by Perkin »

I'd seen that and use the compiler directive in newer code.

But when compiling now, the compile is halted with a warning. What I would like is it to continue compiling, as long as the structure is the same as previous definition.

Maybe still put up a warning, but still continue.

Similar to a Constant being defined previously.
%101010 = $2A = 42
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Structure - Already defined

Post by Josh »

i'm thinking about this problem since some days. when i'm writing reusable code in pbi-files, each file has to contain structures, interfaces, constants ... are needed to run code.

to use Defined(Name, Typ) is bull sh..., because when there is a different structure/interface with the same name in a other pbi-file, you will have large problems and it can be very hard to find the bug. on the other side, what is the same function? are this both interfaces the same or not?

Code: Select all

Interface XYZ
  Test (*X)
EndInterface

Code: Select all

Interface XYZ
  Test (*X.IUnknown)
EndInterface
for iid's i'm using the following code:

Code: Select all

      CompilerIf Defined (IID_IUnknown, #PB_Constant) = #False
        IID_IUnknown:
        Data.l $00000000
        Data.w $0000,$0000
        Data.b $C0,$00,$00,$00,$00,$00,$00,$46
      CompilerEndIf
      #IID_IUnknown = "00000000-0000-0000-C000-000000000046"
in this case, the compiler has no problems, when the iid is already defined in a other pbi-file. additionally i can be sure, that the value of the iid is the same as in the other pbi-file.

i havn't tested, but maybe i will use the same system for structures/interfaces. i will make a little program, that's making a simple hashvalue from the structures/interfacetext. when i'm using this hashvalue in the constant, i can be sure, that the structure/interface is the same.

but this workaround doesn't help you with predefined structures/interfaces. so we have to wait for a native solution.
sorry for my bad english
Post Reply