Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
More requests for FreeBASIC
#1
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:
Reply
#2
Code:
Type foobar

type As Integer

End Type


Dim p As foobar

Dim As Integer Ptr y

y = cptr( Integer Ptr, @p )

y[0] = 38749


? p.type


Sleep

baad baad practice ;P

btw, post this on http://www.freebasic.net if you want more people (including the developers) to see it
Reply
#3
#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?
Reply
#4
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:
Reply
#5
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.
Reply
#6
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:
Reply
#7
I think you're confusing BASIC with C++.
Reply
#8
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.
Reply
#9
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.
Reply
#10
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"]
[Image: yagl1.png]
[/quote]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)