I tried to declaration this to C programming, but it turns out an error. Is there a mistake from this?
poker_comp.c: In function ‘newdeck’:
poker_comp.c:40:15: warning: assignment to ‘Card *’ {aka ‘struct card *’} from incompatible pointer type ‘Card *’ {aka ‘struct card *’} [-Wincompatible-pointer-types]
40 | deck->top = newcard(p,s);
| ^
poker_comp.c:41:12: warning: assignment to ‘Card ’ {aka ‘struct card *’} from incompatible pointer type ‘Card *’ {aka ‘struct card **’} [-Wincompatible-pointer-types]
41 | cursor = deck->top;
| ^
typedef enum boolean {false, true} flipped;`
typedef struct card{
int pips;
char suit;
bool flipped;
int *nextCard;
}Card;
typedef struct deck{
struct card[52];
Card **cards;
}Deck;
typedef struct player{
char name;
int *c1, *c2;
int acc;
}Player;
typedef enum boolean {false, true} flipped;`
is ending with a backquote, and that is wrong.
struct card[52];
is wrong (and is equivalent to , which is also wrong); maybe you want Card[52];
Card card_deck[52];
and later use card_deck
instead of card
...
If you use GCC (actually GCC 10 on Ubuntu 20) on your code aprilia.c
as gcc -Wall -Wextra -g -c aprilia.c
you get error messages:
gcc -Wall -Wextra -c /tmp/aprilia.c -o /tmp/aprilia.o
aprilia.c:1:44: error: stray ‘`’ in program
1 | typedef enum boolean {false, true} flipped;`
| ^
aprilia.c:9:16: error: expected identifier or ‘(’ before ‘[’ token
9 | struct card[52];
| ^
Refer also to some recent draft C standard, such as n1570 or something newer.
Consider taking inspiration from existing free software coded in C, such as GNU Bash.
Consider also using some static analysis tool, e.g., Frama-C or Clang analyzer (or, perhaps in mid-2021, Bismon).
For tagged union types in C, consider having some union
field inside some struct
.