Skip to content

Commit fab42fa

Browse files
authored
Fix typos and clean up hxcpp pointers page (#186)
* Fix typos in hxcpp pointers guide * Mention ConstStar on cpp pointers page * Clean up punctuation and wording
1 parent 9fae30f commit fab42fa

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

assets/content/cookbook/Other/hxcpp-pointers.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
# Hxcpp Pointers
44

5-
This page covers the differences and use cases of the three main pointer types; `cpp.ConstRawPointer` and `cpp.RawPointer`, `cpp.ConstPointer` and `cpp.Pointer`, and `cpp.Star`.
5+
This page covers the differences and use cases of the three main pointer types:
6+
7+
- `cpp.ConstRawPointer` and `cpp.RawPointer`
8+
- `cpp.ConstPointer` and `cpp.Pointer`
9+
- `cpp.ConstStar` and `cpp.Star`.
610

711
## cpp.RawPointer
812

913
As the name says, just bog standard c pointers. e.g. the following haxe function
1014

1115
```haxe
12-
function foo(cpp.RawPointer<int> bar) {}
16+
function foo(bar:cpp.RawPointer<Int>) {}
1317
```
1418

1519
will produce the following C++ function
@@ -30,11 +34,11 @@ could be externed with the following haxe class and the `foo` variable could be
3034

3135
```haxe
3236
extern class Foo {
33-
var cpp.RawPointer<cpp.UInt8> bar;
37+
var bar:cpp.RawPointer<cpp.UInt8>;
3438
}
3539
```
3640

37-
The downside with these is that its not ergonomic from a haxe pov to represent and consume pointers to objects.
41+
The downside with these is that its not ergonomic in haxe code to represent and consume pointers to objects.
3842

3943
```haxe
4044
extern class Foo {
@@ -47,18 +51,18 @@ function myFunc(foo:cpp.RawPointer<Foo>) {
4751
}
4852
```
4953

50-
They also cannot be used in any situations where Dynamic is expected (explicitely or implicitly).
54+
They also cannot be used in any situations where Dynamic is expected (explicitly or implicitly).
5155

5256
```haxe
53-
Array<cpp.RawPointer<int>> // Will generate code which gives C++ compiler errors.
57+
Array<cpp.RawPointer<Int>> // Will generate code which gives C++ compiler errors.
5458
```
5559

5660
## cpp.Pointer
5761

5862
Similar to the above, but with some key differences. The code they generate does not map directly to pointers, but instead to a special `::cpp::Pointer<T>` struct.
5963

6064
```haxe
61-
function foo(cpp.Pointer<int> p) {}
65+
function foo(p:cpp.Pointer<Int>) {}
6266
```
6367

6468
```cpp
@@ -67,7 +71,7 @@ void foo(::cpp::Pointer<int> p) {}
6771
6872
This type lives on the stack so does not contribute to GC pressure, it also is compatible with Dynamic, so you can pass `cpp.Pointer` types into dynamic places and use them with generic arguments. This type also contains loads of convenience functions for reinterpreting the pointer, arithmetic, conversions to haxe arrays and vectors, etc, etc. There are also member fields for accessing the `cpp.Pointer` as a `cpp.RawPointer` or `cpp.Star`.
6973
70-
It also retains the array access that `cpp.RawPointer` does. On top of this the `::cpp::Pointer` type has implicit to and from conversions for the underlying pointer, which means you can extern the following function
74+
It also retains the array access that `cpp.RawPointer` supports. On top of this the `::cpp::Pointer` type has implicit to and from conversions for the underlying pointer, which means you can extern the following function
7175
7276
```cpp
7377
void foo(int* v) {}
@@ -76,10 +80,10 @@ void foo(int* v) {}
7680
with this haxe function
7781

7882
```haxe
79-
void foo(v:cpp.Pointer<Int>) {}
83+
function foo(v:cpp.Pointer<Int>) {}
8084
```
8185

82-
You don't need to use `cpp.RawPointer` here, you can use `cpp.Pointer` and all the convenience it provides. So why would you ever want to use `cpp.RawPointer` if `cpp.Pointer` does everything it does and is compatible with more of haxe's type system.
86+
You don't need to use `cpp.RawPointer` here, you can use `cpp.Pointer` and all the convenience it provides. So why would you ever want to use `cpp.RawPointer` if `cpp.Pointer` does everything it does and is compatible with more of haxe's type system?
8387

8488
Function signatures.
8589

@@ -93,20 +97,19 @@ void foo(bar func) {}
9397
9498
you could not use the following haxe function to generate a function pointer to pass into it.
9599
96-
```
97-
function haxe_foo(cpp.Pointer<int> v) {}
100+
```haxe
101+
function haxe_foo(v:cpp.Pointer<Int>) {}
98102
99103
function main() {
100104
cpp.Callable.fromStaticFunction(haxe_foo);
101105
}
102-
103106
```
104107

105108
That `fromStaticFunction` call will generate a function pointer with the signature of `void(*)(::cpp::Pointer<int>)` which is not compatible with the function pointer `bar`.
106109

107110
## cpp.Star
108111

109-
This is the last pointer types and like `cpp.RawPointer` it generates raw C pointers in the output code, the key difference is that this type does not support array access and will auto de-reference when accessing the underlying data. This means it's ideal for representing pointers to objects. E.g. the following C++
112+
This is the last pointer type and like `cpp.RawPointer` it generates raw C pointers in the output code. The key difference is that this type does not support array access and will auto de-reference when accessing the underlying data. This means it's ideal for representing pointers to objects. E.g. the following C++
110113

111114
```c++
112115
struct Bar {

0 commit comments

Comments
 (0)