We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Giving CxGo a hard time to explore this tool.
#include <stdio.h> int main() { int array3D[3][3][3]; int (*pArray3D)[3][3] = array3D; int i, j, k; for ( i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { for (k = 0; k < 3; k++) { *(*(*(pArray3D + i) + j) + k) = 5; } } } printf("Test: %.d\n", pArray3D[0][0][0]); return 0; }
package main import ( "github.com/gotranspile/cxgo/runtime/stdio" "os" "unsafe" ) func main() { var ( array3D [3][3][3]int pArray3D *[3][3]int = (*[3][3]int)(unsafe.Pointer(&array3D[0][0][0])) i int j int k int ) for i = 0; i < 3; i++ { for j = 0; j < 3; j++ { for k = 0; k < 3; k++ { *unsafe.Pointer(uintptr((*((*[3][3]int)(unsafe.Add(unsafe.Pointer(pArray3D), unsafe.Sizeof([3][3]int{})*uintptr(i)))))[j][0] + k)) = 5 } } } stdio.Printf("Test: %.d\n", (*(*[3][3]int)(unsafe.Add(unsafe.Pointer(pArray3D), unsafe.Sizeof([3][3]int{})*0)))[0][0]) os.Exit(0) }
./runner.go:20:6: invalid operation: cannot indirect unsafe.Pointer(uintptr((*((*[3][3]int)(unsafe.Add(unsafe.Pointer(pArray3D), unsafe.Sizeof([3][3]int{}) * uintptr(i)))))[j][0] + k)) (value of type unsafe.Pointer)
Invalid Pointer dereferencing for 3D arrays. But, for 2D array version of the source C code, CxGo pdouces correct Go code.
package main import ( "github.com/gotranspile/cxgo/runtime/stdio" "os" "unsafe" ) func main() { var ( array3D [3][3][3]int pArray3D *[3][3]int = (*[3][3]int)(unsafe.Pointer(&array3D[0][0][0])) i int j int k int ) for i = 0; i < 3; i++ { for j = 0; j < 3; j++ { for k = 0; k < 3; k++ { //derefencing has been modified here (*(*[3][3]int)(unsafe.Add(unsafe.Pointer(pArray3D), unsafe.Sizeof([3][3]int{})*uintptr(i))))[j][k] = 5 } } } stdio.Printf("Test: %.d\n", (*(*[3][3]int)(unsafe.Add(unsafe.Pointer(pArray3D), unsafe.Sizeof([3][3]int{})*0)))[0][0]) os.Exit(0) }
The text was updated successfully, but these errors were encountered:
dennwc
No branches or pull requests
Giving CxGo a hard time to explore this tool.
Source C code:
Translated Go Code
Go build Failure
Root Cause:
Invalid Pointer dereferencing for 3D arrays. But, for 2D array version of the source C code, CxGo pdouces correct Go code.
Modification that worked
The text was updated successfully, but these errors were encountered: