Posts: 324
Threads: 12
Joined: Nov 2005
1. const variables and pointers (not just compile-time constants)
Quote:dim as integer i = 420
dim as const integer const_i = 69
dim as integer ptr pointer_to_i = @i
dim as integer const ptr const_pointer_to_i = @i
dim as const integer ptr pointer_to_const_i = @const_i
dim as const integer const ptr const_pointer_to_const_i = @const_i
2. alternate syntax for typedefs
Quote:type integer_type as integer
type as integer_type ptr pointer_to_integer_type
3. Incidently, what is this supposed to do (compiles and runs no problem)?
Quote:type foobar
type as integer
end type
stylin:
Posts: 979
Threads: 27
Joined: Aug 2001
#1 makes no sense. If you have a runtime constant with a location in memory, that would make it a... variable?
#2 I can live with out, but it makes sense.
#3, keywords are allowed as type fields. myfoobar.type is an integer. Nifty, eh?
Posts: 324
Threads: 12
Joined: Nov 2005
Quote:#1 makes no sense. If you have a runtime constant with a location in memory, that would make it a... variable?
Precisely - a variable that cannot be modified. What if you have a function parameter that you don't want to change? You can pass it by value, but then if the object is big, you'll have to deal with the expensive copying; that's one of the reasons why we pass by reference in the first place. The only option is to pass it as a
const reference.
Quote:#3, keywords are allowed as type fields. myfoobar.type is an integer. Nifty, eh?
Ahh, I see. I won't comment on the consistency issue here (or lack thereof).
stylin:
Posts: 979
Threads: 27
Joined: Aug 2001
Yes, but that's not possible. If something's in memory, it can be manipulated, and if it's a constant definition, it can't be in memory so you can't have a pointer to it.
Posts: 324
Threads: 12
Joined: Nov 2005
Quote:Yes, but that's not possible. If something's in memory, it can be manipulated, and if it's a constant definition, it can't be in memory so you can't have a pointer to it.
Funny, I do it in C++ all the time ... :???:
I think you're confusing constant variable with a MACRO or #define. The two concepts simply aren't the same. Constant variables do indeed exist in memory, and can be addressed. Think of the word constant as a
qualifier, not a type, and I think you'll start to get me.
stylin:
Posts: 1,752
Threads: 21
Joined: Jun 2002
I think you're confusing BASIC with C++.
Posts: 1,774
Threads: 62
Joined: Aug 2003
Man, personally, I'd much rather see operator overloading implemented than something like this. It looks to me like it would be alot of work... and very confusing on top of that.
Posts: 979
Threads: 27
Joined: Aug 2001
I'm not confused. In C++, a const is a define with type checking. However, if you create a const pointer, it allocates space and then just pretends it's special. But it's only compile-time pretending, there's no speed boost to it.
Posts: 602
Threads: 27
Joined: Oct 2004
Quote:Jofers Wrote:Yes, but that's not possible. If something's in memory, it can be manipulated, and if it's a constant definition, it can't be in memory so you can't have a pointer to it.
Funny, I do it in C++ all the time ... :???:
I think you're confusing constant variable with a MACRO or #define. The two concepts simply aren't the same. Constant variables do indeed exist in memory, and can be addressed. Think of the word constant as a qualifier, not a type, and I think you'll start to get me.
const references in c++ are a way to limit the usage of an object. all methods declared as const of a class can still be called from within a const reference context. those methods can change the the contents of an object...
quote="NecrosIhsan"]
[/quote]