Added LTO and fixed warnings
This commit is contained in:
parent
3e450b5909
commit
15fb694d7b
3 changed files with 25 additions and 20 deletions
10
connect4.c
10
connect4.c
|
|
@ -128,10 +128,10 @@ int main( int argc, char *argv[] ){
|
|||
}
|
||||
return 0;
|
||||
case 'c': // --columns
|
||||
playboard.columns = atoi(optarg);
|
||||
playboard.columns = (columnsint_t)atoi(optarg);
|
||||
break;
|
||||
case 'r': // --rows
|
||||
playboard.rows = atoi(optarg);
|
||||
playboard.rows = (rowsint_t)atoi(optarg);
|
||||
break;
|
||||
case 'o':
|
||||
filename = strdup(optarg);
|
||||
|
|
@ -169,6 +169,10 @@ int main( int argc, char *argv[] ){
|
|||
// Allocate the board
|
||||
playboard.height = calloc( playboard.columns, sizeof(rowsint_t) );
|
||||
playboard.column = calloc( playboard.columns, sizeof(column_t) );
|
||||
if( playboard.height == NULL || playboard.column == NULL ){
|
||||
fprintf( stderr, "ERROR: COULD NOT ALLOCATE BOARD" );
|
||||
return 1;
|
||||
}
|
||||
// Initialize wins struct if used
|
||||
if( wins != NULL ){
|
||||
wins->win0 = calloc( playboard.columns, sizeof(column_t) );
|
||||
|
|
@ -181,7 +185,9 @@ int main( int argc, char *argv[] ){
|
|||
wins->same.horizontal4 = calloc( playboard.columns, sizeof(column_t) );
|
||||
wins->same.diagonalUp4 = calloc( playboard.columns, sizeof(column_t) );
|
||||
wins->same.diagonalDown4 = calloc( playboard.columns, sizeof(column_t) );
|
||||
goto init_ui;
|
||||
}
|
||||
init_ui:
|
||||
initBoard( playboard );
|
||||
// Begin loopin
|
||||
if( outputfile != NULL ){
|
||||
|
|
|
|||
9
makefile
9
makefile
|
|
@ -4,7 +4,7 @@
|
|||
ARCH = native
|
||||
|
||||
# Optimization level
|
||||
O = 2
|
||||
O = s
|
||||
|
||||
# Flags for the compiler
|
||||
FLAGS = -std=c23
|
||||
|
|
@ -17,15 +17,16 @@ endif
|
|||
FLAGS += -pedantic
|
||||
FLAGS += -Wall
|
||||
FLAGS += -Wextra
|
||||
FLAGS += -Werror
|
||||
#FLAGS += -Werror
|
||||
FLAGS += -Wconversion
|
||||
FLAGS += -Wmissing-prototypes
|
||||
FLAGS += -Wlogical-op
|
||||
FLAGS += -Wdisabled-optimization
|
||||
FLAGS += -fanalyzer
|
||||
FLAGS += -flto
|
||||
# These flags are because of the compiler otherwise giving too much warning
|
||||
FLAGS += -Wno-sign-conversion
|
||||
FLAGS += -Wformat-truncation=0
|
||||
#FLAGS += -Wno-sign-conversion
|
||||
#FLAGS += -Wformat-truncation=0
|
||||
|
||||
# Compile flag for defining GITHASH to put at the end of the version string
|
||||
GITFLAG = -D'GITHASH=$(shell git rev-parse --short=1 HEAD)'
|
||||
|
|
|
|||
26
ui_ncurses.c
26
ui_ncurses.c
|
|
@ -71,7 +71,6 @@ void initBoard( const board_t board ){
|
|||
keypad(stdscr, TRUE);
|
||||
nonl();
|
||||
echo();
|
||||
__attribute__((assume(board.columns < 999)));
|
||||
for( columnsint_t column = 0; column < board.columns; column++ ){
|
||||
char colnum[4];
|
||||
snprintf(
|
||||
|
|
@ -79,37 +78,36 @@ void initBoard( const board_t board ){
|
|||
);
|
||||
mvaddstr(
|
||||
BOARD_Y,
|
||||
BOARD_X + BOARD_DX * ( column + 1 ),
|
||||
(int)(BOARD_X + BOARD_DX * ( column + 1 )),
|
||||
colnum
|
||||
);
|
||||
for( rowsint_t row = 0; row < board.rows; row++ ){
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( row + 1 ),
|
||||
BOARD_X + BOARD_DX * ( column + 1 ),
|
||||
(int)(BOARD_Y + BOARD_DY * ( row + 1 )),
|
||||
(int)(BOARD_X + BOARD_DX * ( column + 1 )),
|
||||
"[ ]"
|
||||
);
|
||||
}
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( board.rows + 1 ),
|
||||
BOARD_X + BOARD_DX * ( column + 1 ),
|
||||
(int)(BOARD_Y + BOARD_DY * ( board.rows + 1 )),
|
||||
(int)(BOARD_X + BOARD_DX * ( column + 1 )),
|
||||
colnum
|
||||
);
|
||||
}
|
||||
for( rowsint_t row = 0; row < board.rows; row++ ){
|
||||
char rownum[4];
|
||||
const int intToPrint = board.rows - row + FIRST_NUMBER - 1;
|
||||
__attribute__((assume(intToPrint <= 256)));
|
||||
snprintf(
|
||||
rownum, sizeof(rownum), "%2d", intToPrint
|
||||
);
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( row + 1 ),
|
||||
(int)(BOARD_Y + BOARD_DY * ( row + 1 )),
|
||||
BOARD_X,
|
||||
rownum
|
||||
);
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( row + 1 ),
|
||||
BOARD_X + BOARD_DX * ( board.columns + 1 ),
|
||||
(int)(BOARD_Y + BOARD_DY * ( row + 1 )),
|
||||
(int)(BOARD_X + BOARD_DX * ( board.columns + 1 )),
|
||||
rownum
|
||||
);
|
||||
}
|
||||
|
|
@ -142,8 +140,8 @@ void updateBoard(
|
|||
){
|
||||
rowsint_t height = board.height[ column ];
|
||||
mvaddstr(
|
||||
BOARD_Y + BOARD_DY * ( board.rows - height + 1 ),
|
||||
BOARD_X + 1 + BOARD_DX * ( column + 1 ),
|
||||
(int)(BOARD_Y + BOARD_DY * ( board.rows - height + 1 )),
|
||||
(int)(BOARD_X + 1 + BOARD_DX * ( column + 1 )),
|
||||
board.column[ column ] & 1 << ( height - 1 ) ? "1" : "0"
|
||||
);
|
||||
char num[4];
|
||||
|
|
@ -226,8 +224,8 @@ columnsint_t askColumn(
|
|||
}
|
||||
for(;;){
|
||||
int ch = mvgetch(
|
||||
BOARD_Y + BOARD_DY * ( board.rows - board.height[ column ] ),
|
||||
BOARD_X + 1 + BOARD_DX * ( column + 1 )
|
||||
(int)(BOARD_Y + BOARD_DY * ( board.rows - board.height[ column ] )),
|
||||
(int)(BOARD_X + 1 + BOARD_DX * ( column + 1 ))
|
||||
);
|
||||
switch( ch ){
|
||||
case KEY_RIGHT:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue