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