Skip to content
New issue

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

Compile knightstour.c #67

Closed
9 tasks done
elliotchance opened this issue Apr 24, 2017 · 19 comments
Closed
9 tasks done

Compile knightstour.c #67

elliotchance opened this issue Apr 24, 2017 · 19 comments

Comments

@elliotchance
Copy link
Owner

elliotchance commented Apr 24, 2017

This was an issue raise originally by @carstenhag with #27.

The original ticket was fixed but the example program was very good. This issue will outline what we need to do to get knightstour.c working.

@Konstantin8105
Copy link
Contributor

After checking, Transpiling that file without panic with just 32 warnings.

@elliotchance
Copy link
Owner Author

Please post the warnings so we can create issues out of them.

@carstenhag
Copy link

Warnings given out by c2go, I've omitted some redundant ones:

// Warning (TypedefDecl): 0: I couldn't find an appropriate Go type for the C type '__NSConstantString_tag'.
// Warning (FieldDecl): 58: function pointers are not supported
// Warning (FieldDecl): 133: function pointers are not supported
// Warning (VarDecl): 459: probably an incorrect type translation 2
// Warning (FieldDecl): 172: function pointers are not supported
// Warning (RecordDecl): 199: could not parse &{140276283397408 {/usr/include/sys/wait.h 199 212 2 2 }  line:199:2 struct  true [0xc4204dfc20 0xc4204dfcc0 0xc4204dfd60 0xc4204dfe00]}
// Warning (FieldDecl): 199: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/sys/wait.h:199:2)'.
// Warning (RecordDecl): 218: could not parse &{140276283398248 {/usr/include/sys/wait.h 218 229 2 2 }  line:218:2 struct  true [0xc4204dff40 0xc420898b40 0xc420898be0]}
// Warning (FieldDecl): 218: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/sys/wait.h:218:2)'.
// Warning (RecordDecl): 194: could not determine the size of type `union wait` for that reason: cannot determine size of: ``
// Warning (MemberExpr): 663: cannot determine type for LHS 'const struct __float2', will use 'void *' for all fields
// Warning (MemberExpr): 663: cannot determine type for LHS 'const struct __float2', will use 'void *' for all fields
// Warning (MemberExpr): 668: cannot determine type for LHS 'const struct __double2', will use 'void *' for all fields
// Warning (MemberExpr): 668: cannot determine type for LHS 'const struct __double2', will use 'void *' for all fields
// Warning (MemberExpr): 673: cannot determine type for LHS 'const struct __float2', will use 'void *' for all fields
// Warning (MemberExpr): 673: cannot determine type for LHS 'const struct __float2', will use 'void *' for all fields
// Warning (MemberExpr): 678: cannot determine type for LHS 'const struct __double2', will use 'void *' for all fields
// Warning (MemberExpr): 678: cannot determine type for LHS 'const struct __double2', will use 'void *' for all fields
// Warning (MemberExpr): 31: cannot determine type for LHS 'coord', will use 'void *' for all fields
// Warning (MemberExpr): 31: cannot determine type for LHS 'coord', will use 'void *' for all fields

// Warning (MemberExpr): 142: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 149: cannot determine type for LHS 'void *', will use 'void *' for all fields
// Warning (MemberExpr): 149: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 149: cannot determine type for LHS 'void *', will use 'void *' for all fields
// Warning (MemberExpr): 150: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 150: cannot determine type for LHS 'void *', will use 'void *' for all fields
// Warning (MemberExpr): 150: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 150: cannot determine type for LHS 'void *', will use 'void *' for all fields
// Warning (MemberExpr): 180: cannot determine type for LHS 'coord', will use 'void *' for all fields
// Warning (ImplicitValueInitExpr): 192: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 192: cannot transpile to expr
// Warning (MemberExpr): 203: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 204: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (UnaryExprOrTypeTraitExpr): 210: cannot determine size of: `extCoord`
// Warning (CallExpr): 210: function pointers are not supported
// Warning (MemberExpr): 213: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 214: cannot determine type for LHS 'extCoord', will use 'void *' for all fields
// Warning (MemberExpr): 258: cannot determine type for LHS 'coord', will use 'void *' for all fields
// Warning (MemberExpr): 258: cannot determine type for LHS 'coord', will use 'void *' for all fields
// Warning (UnaryExprOrTypeTraitExpr): 288: cannot determine size of: `_Bool`
// Warning (UnaryExprOrTypeTraitExpr): 288: cannot determine size of: `_Bool`
// Warning (CallExpr): 322: Cannot resolve function : I couldn't find an appropriate Go type for the C type '...'.

When building it, it doesn't recognize what coord is.

~/D/knightstour-c2go λ go build knightstour.go
# command-line-arguments
./knightstour.go:957:21: undefined: coord
./knightstour.go:960:22: undefined: coord
./knightstour.go:967:22: undefined: coord
./knightstour.go:970:65: undefined: coord
./knightstour.go:1003:25: undefined: coord
./knightstour.go:1011:33: undefined: coord
./knightstour.go:1048:32: undefined: coord
./knightstour.go:1108:27: undefined: coord
./knightstour.go:1111:32: undefined: coord
./knightstour.go:1118:38: undefined: coord
./knightstour.go:1118:38: too many errors

@carstenhag
Copy link

carstenhag commented Nov 7, 2017

Full warnings: warnings.txt

@carstenhag
Copy link

type coord struct {
	x int
	y int
}

type extCoord struct {
	position      coord
	possibleSteps int
}

Should have been included into the go file.

@Konstantin8105
Copy link
Contributor

@carstenhag , thanks, I will check later, again.

@Konstantin8105
Copy link
Contributor

Present result:

// Warning (FieldDecl): 85: probably an incorrect type translation 3
// Warning (TypedefDecl): 333: function pointers are not supported
// Warning (TypedefDecl): 341: function pointers are not supported
// Warning (TypedefDecl): 350: function pointers are not supported
// Warning (TypedefDecl): 353: function pointers are not supported
// Warning (FieldDecl): 69: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:69:5)'.
// Warning (FieldDecl): 84: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:84:5)'.
// Warning (RecordDecl): 66: could not determine the size of type `union wait` for that reason: cannot determine size of: `struct (anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:84:5)`
// Warning (TransparentUnionAttr): 71: could not parse &{55956192 {/usr/include/stdlib.h 71 0 35 0 } []}
// Warning (FieldDecl): 141: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:141:3)'.
// Warning (FieldDecl): 177: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:177:3)'.
// Warning (TypedefDecl): 741: function pointers are not supported
// Warning (EnumDecl): 209: Add support of continues counter for type : *ast.BasicLit
// Warning (EnumDecl): 209: Add support of continues counter for type : *ast.BasicLit
// Warning (EnumDecl): 209: Add support of continues counter for type : *ast.BasicLit
// Warning (EnumDecl): 209: Add support of continues counter for type : *ast.BasicLit
// Warning (EnumDecl): 209: Add support of continues counter for type : *ast.BasicLit
// Warning (EnumDecl): 347: Add support of continues counter for type : *ast.UnaryExpr
// Warning (ImplicitValueInitExpr): 192: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 192: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 193: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 193: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 194: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 194: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 195: cannot transpile to expr
// Warning (ImplicitValueInitExpr): 195: cannot transpile to expr
// Warning (UnaryExprOrTypeTraitExpr): 210: cannot determine size of: `extCoord`
// Warning (CallExpr): 210: function pointers are not supported
// Warning (UnaryExprOrTypeTraitExpr): 288: cannot determine size of: `_Bool`
// Warning (UnaryExprOrTypeTraitExpr): 288: cannot determine size of: `_Bool`
// Error (BinaryOperator): 288: cannot determine size of: `_Bool`
// Warning (ForStmt): 0: ForStmt cannot be nil
// Error (WhileStmt): 345: Stmts inside Block cannot be nil
○ → go build king.go
# command-line-arguments
./king.go:479: invalid operation: board + pos.y * sizeX (mismatched types []bool and int)
./king.go:485: invalid operation: board + pos.y * sizeX (mismatched types []bool and int)
./king.go:522: invalid operation: steps + pos.y * sizeX (mismatched types []int and int)
./king.go:527: missing return at end of function
./king.go:554: undefined: noarch.InterfaceToExtCoordSlice
./king.go:555: undefined: noarch.InterfaceToExtCoordSlice
./king.go:587: cannot use nil as type coord in field value
./king.go:604: undefined: qsort
./king.go:666: undefined: sprintf
./king.go:667: undefined: strcat
./king.go:667: too many errors

@Konstantin8105
Copy link
Contributor

Konstantin8105 commented Dec 18, 2017

After #469:

// Warning (FieldDecl): 85: probably an incorrect type translation 3
// Warning (TypedefDecl): 333: function pointers are not supported [2] : '__ssize_t (void *, char *, size_t)'
// Warning (TypedefDecl): 341: function pointers are not supported [2] : '__ssize_t (void *, char *, size_t)'
// Warning (TypedefDecl): 350: function pointers are not supported [2] : 'int (void *, __off64_t *, int)'
// Warning (TypedefDecl): 353: function pointers are not supported [2] : 'int (void *)'
// Warning (FieldDecl): 69: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-l
inux-gnu/bits/waitstatus.h:69:5)'.
// Warning (FieldDecl): 84: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-l
inux-gnu/bits/waitstatus.h:84:5)'.
// Warning (RecordDecl): 66: could not determine the size of type `union wait` for that reason: cannot determine size of: `st
ruct (anonymous struct at /usr/include/x86_64-linux-gnu/bits/waitstatus.h:84:5)`
// Warning (TransparentUnionAttr): 71: could not parse &{56341216 {/usr/include/stdlib.h 71 0 35 0 } []}
// Warning (FieldDecl): 141: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-
linux-gnu/bits/pthreadtypes.h:141:3)'.
// Warning (FieldDecl): 177: I couldn't find an appropriate Go type for the C type '(anonymous struct at /usr/include/x86_64-
linux-gnu/bits/pthreadtypes.h:177:3)'.
// Warning (TypedefDecl): 741: function pointers are not supported [1] : 'int (*)( void *, void *)'
// Warning (EnumDecl): 347: Add support of continues counter for type : *ast.UnaryExpr
// Error (VarDecl): 140: I couldn't find an appropriate Go type for the C type 'extCoord':'extCoord'.
// Error (VarDecl): 141: I couldn't find an appropriate Go type for the C type 'extCoord':'extCoord'.
// Warning (UnaryExprOrTypeTraitExpr): 210: cannot determine size of: `extCoord`
// Warning (CallExpr): 210: function pointers are not supported [2] : 'int ( void *, void *)'
// Warning (UnaryOperator): 328: Cannot transpile UnaryOperator: err = Not acceptable : change counter is more then 1. found 
= &{56899224 {king.c 328 0 36 0 } int *  true Var 0x3638558 steps int *  []},&{56899536 {king.c 328 0 54 0 } int  LValueToRVa
lue [0xc420225a40]}
// Warning (BinaryOperator): 328: Cannot transpile BinaryOperator : result type = {unknown52}. Error: Cannot transpile UnaryO
perator: err = Not acceptable : change counter is more then 1. found = &{56899224 {king.c 328 0 36 0 } int *  true Var 0x3638
558 steps int *  []},&{56899536 {king.c 328 0 54 0 } int  LValueToRValue [0xc420225a40]}
// Error (CallExpr): 328: Cannot transpile BinaryOperator : result type = {unknown52}. Error: Cannot transpile UnaryOperator:
 err = Not acceptable : change counter is more then 1. found = &{56899224 {king.c 328 0 36 0 } int *  true Var 0x3638558 step
s int *  []},&{56899536 {king.c 328 0 54 0 } int  LValueToRValue [0xc420225a40]}
○ → go build king.go 
# command-line-arguments
./king.go:443: missing return at end of function
./king.go:525: undefined: qsort
./king.go:598: undefined: sprintf
./king.go:599: undefined: strcat
./king.go:600: undefined: strcat
./king.go:666: missing return at end of function
./king.go:678: invalid operation: noarch.Strlen(option) + uint32(12) (mismatched types int and uint32)
./king.go:679: undefined: malloc
./king.go:680: undefined: malloc
./king.go:681: undefined: strcat
./king.go:681: too many errors

@Konstantin8105
Copy link
Contributor

For present version c2go list of warning is not important, because all warning from standard C library, but not in user code.
Result of go build:

○ → go build king.go
# command-line-arguments
./king.go:474:1: missing return at end of function
./king.go:554:2: undefined: qsort
./king.go:623:2: undefined: sprintf
./king.go:624:2: undefined: strcat
./king.go:625:2: undefined: strcat
./king.go:692:1: missing return at end of function
./king.go:705:26: undefined: malloc
./king.go:706:26: undefined: malloc
./king.go:707:2: undefined: strcat
./king.go:708:2: undefined: strcat
./king.go:708:2: too many errors

@Konstantin8105
Copy link
Contributor

Konstantin8105 commented Jan 5, 2018

Dear @elliotchance ,
After #535 and #531 , that code "knighttour.c" is executable.

 2018-01-05 21:56:26 ⌚  lepricon-AOD270 in ~/go/bin/king
○ → c2go transpile king.c

 2018-01-05 22:04:51 ⌚  lepricon-AOD270 in ~/go/bin/king
○ → go build king.go

 2018-01-05 22:04:55 ⌚  lepricon-AOD270 in ~/go/bin/king
○ → ./king
1: Startfeld wird vom Programm gewählt.
2: Startfeld wird vom Anwender frei gewählt.
3: Startfeld wird vom Anwender frei gewählt, der Springer geht einen geschlossenen Pfad.
Wählen Sie bitte zwischen den Optionen 1, 2 und 3 aus: 

But, I have not idea - How to test?

@carstenhag
Copy link

carstenhag commented Jan 5, 2018

Hey @Konstantin8105 and the others, thanks for improving c2go so much that it even builds now!
knightstour.c has been implemented by 2 friends and me for a university assignment.

It's about (as the name says :P) the Knight's Tour problem.

The first option uses the position (1,1) (1-indexed) and lets you choose a board size.
The second options lets you chose both the starting position and the board size.
The third option lets you chose both, and the knight tries to make a closed tour (info on that in the wiki article).

You can compare the transpiled version with the original C one.
knightstour.c is compiled with gcc main.c -o out -O3 --std=c99 -lm -Wall -Werror.

Verifying that the output is right is relatively easy, just follow the step numbers like a knight would/could:

Screenshot of the program

@carstenhag
Copy link

@Konstantin8105 I tried to run it with your mallocIssue67 branch, https://github.com/Konstantin8105/c2go/tree/mallocIssue67, but it seems to give me the following errors:

~/g/s/g/K/c2go (mallocIssue67|…) λ go build knightstour.go
# command-line-arguments
./knightstour.go:1329:26: undefined: malloc
./knightstour.go:1330:26: undefined: malloc

@Konstantin8105
Copy link
Contributor

Dear @carstenhag , please wait little bit for transpilation, because 2 PR are on review.
Could you prepare some tests in according to gcc version

@carstenhag
Copy link

I'm not quite sure what you mean with "prepare some tests in according to gcc version", but I've just compiled the c program on gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) on ubuntu and "gcc"/clang on macOS:

~/g/springer-c2gotest λ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)

@Konstantin8105
Copy link
Contributor

for example if I execute gcc version of that program and chose 1 in menu - What I will can enter for success?

@carstenhag
Copy link

carstenhag commented Jan 5, 2018

Ooh sorry, I forgot that. Option 1, Board Size (x): 8, Board Size (y): 8 should find a solution almost instantly. In general, open solutions with board sizes below 20x20 should be almost-instant (application is memory-bottlenecked at very large sizes)

@Konstantin8105
Copy link
Contributor

@carstenhag , thank you for clarification. We will return to that discussion later.

@Konstantin8105
Copy link
Contributor

Dear @elliotchance , @carstenhag ,
In according to present version of c2go, test case of knightstour.c is good.
Results of Go and C is not identical, because (in my point of view) different algorithm of sorting.
Feel free for comments.
(We can close that issue).

Result of Go program:

 2018-01-14 15:34:47 ⌚  lepricon-AOD270 in ~/go/bin/king
○ → go run king.go 
1: Startfeld wird vom Programm gewählt.
2: Startfeld wird vom Anwender frei gewählt.
3: Startfeld wird vom Anwender frei gewählt, der Springer geht einen geschlossenen Pfad.
Wählen Sie bitte zwischen den Optionen 1, 2 und 3 aus: 1
Board Size (x): 5
Board Size (y): 6
Starting at Position (1,1).

A solution has been found!

Solution Steps:

01  16  19  26  03  10  

18  25  02  09  20  27  

15  08  17  24  11  04  

30  23  06  13  28  21  

07  14  29  22  05  12  

Result of C program:

 2018-01-14 15:54:09 ⌚  lepricon-AOD270 in ~/go/bin/king
○ → ./out
1: Startfeld wird vom Programm gewählt.
2: Startfeld wird vom Anwender frei gewählt.
3: Startfeld wird vom Anwender frei gewählt, der Springer geht einen geschlossenen Pfad.
Wählen Sie bitte zwischen den Optionen 1, 2 und 3 aus: 1
Board Size (x): 5
Board Size (y): 6
Starting at Position (1,1).

A solution has been found!

Solution Steps:

01  16  21  28  07  14  

22  29  08  15  20  27  

09  02  17  24  13  06  

30  23  04  11  26  19  

03  10  25  18  05  12  

@elliotchance
Copy link
Owner Author

That's so awesome @Konstantin8105! I'm happy to close this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants