Skip to content
Paul Squires edited this page Oct 19, 2026 · 2 revisions

Home › Converting Data Types › CPtr

CPtr

Converts a pointer or an integer to the given pointer type.

Syntax

CPtr( PointerDataType, expression )

Description

Converts expression to PointerDataType.

PointerDataType must be a Pointer type (e.g. a DataType Ptr or an Any Ptr), or a Type (Alias) to one.
expression may have a different pointer type or be an Integer.

Note: Currently, FB does not actually enforce thatPointerDataTypemust be a pointer. This will likely change in future versions though. Currently, it may display a warning if you try to convert to a non-pointer (for any conversion type if you compile with the -w pedantic compiler switch).

Remarks

Dialect Differences

  • Not available in the -lang qb dialect unless referenced with the alias __Cptr.

Differences from QB

  • New to FreeBASIC

See also

Examples

Dim intval As Integer

Dim intptr As Integer Ptr

intval = &h0080

intptr = @intval

'' will print -128 and 128, as the first expression will be "seen" as an signed byte

Print *CPtr( Byte Ptr, intptr ), *intptr

Category: Converting Data Types
Kind: keyword


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally