Program in correct switches

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Program in correct switches

Post by blueb »

Instead of always reminding the user to apply a certain compiler switch:

CompilerIf #PB_Compiler_Thread = 0
MessageRequester("Warning","Without Threadsafe... this won't work!")
CompilerEndIf


If the program needs a switch to run properly, why can't the programmer just write:

#PB_Compiler_Thread = 1
or...
SetSwitch(#PB_Compiler_Thread, 1)
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Program in correct switches

Post by GPI »

That will not solve your problem, but maybe this would be a better solution.

Code: Select all

CompilerIf #PB_Compiler_Thread=0
  (0/1) "please activate ThreadSave in the Compiler Options"
CompilerEndIf
When the flag is not activated, the compiler stops in the line with a Syntax error, otherwise it compile correctly.

Maybe the Problem is,that when the "Switch" is not at the begin of you SoureCode, it must stop compiling and start from the beginning. Also maybe a Problem, when you activate and deactivate the switch at diffrent position in your source code.
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Program in correct switches

Post by kenmo »

There is CompilerError for that purpose:

Code: Select all

CompilerIf (Not #PB_Compiler_Unicode)
  CompilerError "Please compile in Unicode mode"
CompilerEndIf

blueb, this would be a tricky change, I think, because compile switches like /Unicode are currently passed to the pbcompiler commandline, so it "knows" all the switches before it even starts loading/parsing through your code.
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Program in correct switches

Post by blueb »

Thanks kenmo.

It was only a small request... nothing important.

You're right, the compiler needs to know 'in advance' to reading and executing the code.

Basically, I was thinking that when a person places some code on the forum for other users...

If the compiler was not in the desired mode, it could be done in the code itself, rather than
forcing the user to activate the switches manually.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply