Page 1 of 1

const-pointer possible in PB?

Posted: Mon May 02, 2005 10:48 am
by Escobar
I have some C/C++ code that I want to translate to PB but I'm stuck with a "pointer"-problem.
How do I make an equivalent "const"-pointer in PB?

C-code: const int *pOne;

pOne is a pointer to a constant of Integer-type. The value can't be change.

Now how do I do that in PB?
Would this be valid:

*myptr.int\#

or is it pure rubbish?:wink:


Thanks in advance

Posted: Mon May 02, 2005 11:27 am
by srod
Hiya,

someone will correct me if I'm wrong here, but I think constants in Purebasic are dealt with at the pre-processor stage in that they are simply substitued for their values. Pointers to constants are therefore meaningless in this context!
Would this be valid:

*myptr.int\#

or is it pure rubbish?
The latter is true! :)

Posted: Mon May 02, 2005 12:23 pm
by Bonne_den_kule
Can't you use a variable instead, and get the pointer to it?

Re: const-pointer possible in PB?

Posted: Mon May 02, 2005 12:37 pm
by traumatic
:?:
Sorry, but what are you talking about?

const int *pOne means that while pOne can be changed within a function,
*pOne can not, as only a copy of the pointer is being passed to the function.

To gain a similar behaviour in PB, you'd have to temporarily save the value
and copy it back before exiting the procedure.

Correct me if I'm wrong.

Posted: Mon May 02, 2005 4:11 pm
by tinman
A const pointer is one which you cannot change the value that is being pointed to. For example:

Code: Select all

int foo;
const int *pFoo = &foo;
*pFoo = 23; /* Invalid */
In PB there is no such thing as a const pointer, you only have the normal pointer type. To do it with an int (assuming int in your C compiler is 32 bits, which it probably is under WIndows) you can do this:

Code: Select all

DefType.l foo
DefType.LONG *pOne
*pOne = @foo
*pOne\l = 23