[Resolved] PB 6 and structured variable(s) as argument with #CompilerIf

Just starting out? Need help? Post your questions and find answers here.
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

[Resolved] PB 6 and structured variable(s) as argument with #CompilerIf

Post by boddhi »

Hello,

I've searched (not well perhaps ...) and not found about this :

In PB 5 and older, I usually used structured variables as procedural arguments like this :

Code: Select all

Structure StructVar
  Var1.a
  Var2.s
EndStructure

Procedure ProcedureTest(Variable.StructVar)
  ......
EndProcedure
Now, it seems to be necessary to use a pointer :

Code: Select all

Procedure Procedure(*Variable.StructVar)
  ......
EndProcedure
Is this normal ? Is this due to new PB6 C-backend ?

Thanks.
Last edited by boddhi on Sun Jul 03, 2022 8:27 am, edited 2 times in total.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: PB 6 and structured variable(s) as argument

Post by jacdelad »

Not because of the c backend. I don't know the background, but I gues it doesn't matter anyway, since the variable is a pointer to the memory with the structure.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: PB 6 and structured variable(s) as argument

Post by Little John »

boddhi wrote: In PB 5 and older, I usually used structured variables as procedural arguments like this :

Code: Select all

Structure StructVar
  Var1.a
  Var2.s
EndStructure

Procedure ProcedureTest(Variable.StructVar)
  ......
EndProcedure
That's strange. I can't recall that PB code like this ever worked in the last 15+ years.
As far as I remenber, it was always necessary to use a pointer, like in your second example. Otherwise a syntax error is raised.
Using a pointer when passing a structure as procedure parameter is certainly required with PB 5.73 LTS, for instance.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6 and structured variable(s) as argument

Post by mk-soft »

Structured variables always as ByRef (pointer). Has always been so ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

PB 6 and structured variable(s) as argument with #CompilerIf

Post by boddhi »

Ouupps :oops: , sorry I make a (big !) mistake in reading an old code I made...
(In french, we say literally "Not have eyes in front of the holes !!!" :) )

The problem is quite different, below is a shortcut code of one of my programs running very well with PB5.73 and older.
I tested it with PB6 b9 and had an error, I thought perhaps it was a bug not solved yet but the problem persists with final version :

Code: Select all

Enumeration
  #ATAGS_LANGUAGE_FR
  #ATAGS_LANGUAGE_EN
EndEnumeration

;#ATAGS_LANGUAGE=#ATAGS_LANGUAGE_FR
#ATAGS_LANGUAGE=#ATAGS_LANGUAGE_EN

CompilerIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_FR
  Structure ID3v2_L
    Titre.s
    Artiste.s
  EndStructure
CompilerElseIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_EN
  Structure ID3v2_R
    Title.s
    Artist.s
  EndStructure
CompilerEndIf

CompilerIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_FR ; ATAGSReadID3v1
  Declare.b ATAGSReadID3v2(Fichier.s,*ID3v2Tags.ID3v2_L)
CompilerElseIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_EN
  Declare.b ATAGSReadID3v2(FileName.s,*ID3v2Tags.ID3v2_R)
CompilerEndIf

CompilerIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_FR ; ATAGSReadID3v1
  ProcedureDLL.b ATAGSReadID3v2(Fichier.s,*ID3v2Tags.ID3v2_L) ;- Lit les métadonnées ID3v2 d'un fichier
CompilerElseIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_EN
  ProcedureDLL.b ATAGSReadID3v2(FileName.s,*ID3v2Tags.ID3v2_R) ;- Read ID3v2 metadata of a file
CompilerEndIf
    Debug "Ok"
EndProcedure

CompilerIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_FR
  Define.ID3v2_L *ID3v2Tags
  ATAGSReadID3v2("C:\Temp.txt",*ID3v2Tags.ID3v2_L)
CompilerElseIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_EN
  Define.ID3v2_R *ID3v2Tags
  ATAGSReadID3v2("C:\Temp.txt",*ID3v2Tags.ID3v2_R)
CompilerEndIf
With PB6 a new error message occurs : "Declaration doesn't match procedure definition (DLL procedure inconsistency)"...

Am I doing something wrong ? If you have any idea...
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: PB 6 and structured variable(s) as argument with #CompilerIf

Post by idle »

Change the Declare to DeclareDll

Code: Select all

CompilerIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_FR ; ATAGSReadID3v1
  DeclareDLL.b ATAGSReadID3v2(Fichier.s,*ID3v2Tags.ID3v2_L)
CompilerElseIf #ATAGS_LANGUAGE=#ATAGS_LANGUAGE_EN
  DeclareDLL.b ATAGSReadID3v2(FileName.s,*ID3v2Tags.ID3v2_R)
CompilerEndIf
boddhi
Enthusiast
Enthusiast
Posts: 224
Joined: Mon Nov 15, 2010 9:53 pm

PB 6 and structured variable(s) as argument with #CompilerIf

Post by boddhi »

Hello,

DeclareDll !
So evident !!! Shame on me ! :oops:

It works fine now.
PB 5 was more permissive. For the best or for the worst ! :D

Thanks idle !
Post Reply