Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
More requests for FreeBASIC
#11
Quote:I'm not confused. In C++, a const is a define with type checking.
Hardly. A #define is a symbol that the dumb engine of the preprocessor uses to replace code text. Constants are actual variables! They take up memory, they obey scoping rules, they're type-safe, and they're available if the compiler is smart enough to optimize them out.

Quote:However, if you create a const pointer, it allocates space and then just pretends it's special.
Const integer, const pointer - same thing. Again, they both get memory allocated because they're both variables. Const tells the compiler that the variable cannot be changed in any way. For const pointers, the pointer cannot be reseated. For pointers to const objects, the object cannot be modified in any way, but the pointer can be redirected elsewhere - How do you think we iterate through string literals?

My question was why doesn't BASIC have this capability yet? You seem to be implying that extra compile-time checking is a bad thing.

Quote:But it's only compile-time pretending, there's no speed boost to it.
Who's talking about speed issues?
stylin:
Reply
#12
My bad... After playing a bit with c++ I realize that you are right about the constants, FB is lacking some there. I also thought you were making some kind of assumption that constant pointers would somehow be faster with the "expensive copying" bit.
Reply
#13
Quote:My bad... After playing a bit with c++ I realize that you are right about the constants, FB is lacking some there. I also thought you were making some kind of assumption that constant pointers would somehow be faster with the "expensive copying" bit.
My apologies, then. I was unclear. :oops: I only mentioned the potential hit because there are times when you need to pass a large, unmodifiable variable to a function. There are 3 ways to do this: by value, by pointer to const, and by const reference. The last two being magnitutdes faster and more efficient in many cases since you're only passing a 4-byte pointer (references are implemented differently depending on the compiler, but AFAIK, many do treat them like const pointers, and you'd probably be safe in thinking of them that way).
stylin:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)