Building a DLL - what's real code

Found an issue in the documentation ? Please report it here !

Moderator: Documentation Editors

User avatar
mariosk8s
Enthusiast
Enthusiast
Posts: 103
Joined: Wed Apr 06, 2011 11:37 am
Location: Hüfingen, Germany
Contact:

Building a DLL - what's real code

Post by mariosk8s »

The doc text
The DLL code is like a PureBasic code except than no real code should be written outside of procedure.
tells me that anything that "runs" should be inside of a procedure. This is as intended. I read things that are compile time such as compiler directives and variable and constant declarations are OK. Procedure calls are not.
On Mac OS X, this is a particular problem, while Linux and Windows let you get away with it. This week after a Bus Error head banging session i learned, that

Code: Select all

Global lastIdx = 4
Global Dim someArray.s(lastIdx)
is ok, but the following is not

Code: Select all

someArray.s(0) = "foo"
is not. Both look like variable declarations to me, but apparently the internal purebasic implementation is indeed a function call. I guess Maps are also at risk.

Maybe it would be useful to elaborate a bit on which things are allowed, and which not. By allowed we should focus on the strictest platform, i guess Mac. I above example should definitely be part of that.

I would also be worth mentioning that Mac OS X is really strict on this, and that it'll rain Bus Errors and Segfaults if this rule is violated, and that other platforms are a bit more permissive.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Building a DLL - what's real code

Post by luis »

I would like it too, I asked something similar three years ago -> http://www.purebasic.fr/english/viewtop ... 13&t=42537

As you can see all the threads linked there were not particular satisfying :)
mariosk8s wrote:By allowed we should focus on the strictest platform, i guess Mac.
I disagree here, if more info are given, they should be distinct by platform.
No reason to limit myself on Windows when not needed just because elsewhere something is not permitted.
Knowing all there is to know, I can then make my decisions.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Building a DLL - what's real code

Post by Tenaja »

The reason the second var declaration failed is because you are attempting to initialize it. Initializations include "real code," in this case it is the same as an assignment. If you need to init variables, either static or global, you should do them in an Init proc for the dll.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Building a DLL - what's real code

Post by luis »

Well, even lastIdx has been initialized then.
lastIdx too is initialized with "real code" (a MOV instruction).
The reason is probably the var is of type string, so memory allocation is occurring, something a lot more heavy then a MOV.

That's my guess at least.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Building a DLL - what's real code

Post by Tenaja »

luis wrote:Well, even lastIdx has been initialized then.
lastIdx too is initialized with "real code" (a MOV instruction).
The reason is probably the var is of type string, so memory allocation is occurring, something a lot more heavy then a MOV.

That's my guess at least.
I did miss that other var getting an init value, but even so, is it really getting initailized? Does any code in a dll get executed outside of a proc call? I'd be surprised, because unless Fred's OpenLibrary command forces the main file to execute the "free-form" code, then it will not happen.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Building a DLL - what's real code

Post by luis »

Tenaja wrote: I did miss that other var getting an init value, but even so, is it really getting initailized?
On Windows, yes.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2057
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Building a DLL - what's real code

Post by Andre »

This is something, which Fred should check and clarify in the Docs... 8)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply