Constants

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Constants

Post by luis »

I did a search but the word "constant" is very used as you can guess.

Well, sorry if already requested.


I would like to have a keyword "const" in addition to global, protected and so on.

Something like

Code: Select all

Const myconst.l

Protected Const localconst.l

Global Const globalconst.l


like the classical C/C++ keyword.

Just to get rid of some of the #MYCONST = 1 definitions and to have the ability to define local constants (would be nice) and to have constant parameters to procedures (e.g. constant pointers).

Well, here goes my request!

Thank you.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I'm curious what you would need it for?
it's a while ago I progged in C...

a PB constant is replaced while compile time.

what against using a normal variable and taking care not to alter it?
oh... and have a nice day.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

Kaeru Gaman wrote: a PB constant is replaced while compile time.
and it's only text, that's why you can't have a local const.

Kaeru Gaman wrote:what against using a normal variable and taking care not to alter it?
- well, for once it makes clear the intentions of who wrote the proc:

"this variable is for input only", or read only if you prefer

- you can see that like some additional implicit documentation of the proc, too

- being a variable and not a preprocessor string, you could initialize it using other variables or a function

- const pointers (the pointer is fixed and can point only to the specific location used to initialize it)

- pointers to const (the pointer can't change the data, but the pointer can change and point to other data)

- const pointers to const (the pointer is fixed and can't change the data is pointing to)

and so on ...

:)
Last edited by luis on Tue Nov 25, 2014 11:53 am, edited 1 time in total.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

yo, I get the point. thnx. as I said, just curious.
it can help to have additional support on keeping a variable unchanged, I see.
oh... and have a nice day.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

Yep but not only that: you could have LOCAL consts (now you can't) and you could initialize constants in many ways (directly, using other variables, using procedures). Now you can't.
Last edited by luis on Sun Sep 07, 2008 12:32 pm, edited 1 time in total.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

I see this feature as redundant and necessary. If you want something like this in your own code you can add a keyword to the IDE and parse for it with a pre-compiler.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: Constants

Post by uwekel »

Hi, this is already an old post but this is what i need as well :-)
+1
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re:

Post by luis »

Mistrel wrote:I see this feature as redundant and necessary.
As long it's necessary ... :lol:

Amusement aside, no, it's not redundant at all.
A "Const" type qualifier is totally different from the current search and replace in the source for a literal constant, as it's evident from the examples I've made above.

Probably it will never be implemented, but that's another story.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply