Fix function prototype warnings for C23 compatibility
- Add proper function prototypes: fatal(), my_exit(), set_order() - Fix function pointer types to match call sites: void (*func)(int) - Remove conflicting localtime() declaration in rip.c - Fix incorrect new_item() call in state.c (remove unused argument) Result: Zero compilation warnings, C23 compatible. See MODERNIZATION_LOG.md for detailed analysis.
This commit is contained in:
@@ -61,6 +61,69 @@ move(oy, ox); /* Use public API instead of internal structure access */
|
||||
|
||||
---
|
||||
|
||||
### 2025-01-XX: Fix Function Prototype Warnings (C23 Compatibility)
|
||||
|
||||
**Issue**: Multiple functions declared without prototypes, causing C23 compatibility warnings
|
||||
|
||||
**Location**: Multiple files
|
||||
|
||||
**Problem**:
|
||||
1. Functions declared as `void func();` (old-style) but defined with parameters
|
||||
2. Function pointers without proper prototypes
|
||||
3. Local function declaration conflicting with standard library
|
||||
|
||||
**Root Cause**:
|
||||
- Pre-C99 code used old-style function declarations
|
||||
- C23 requires proper function prototypes
|
||||
- Function pointers need explicit parameter types
|
||||
|
||||
**Solution**:
|
||||
|
||||
1. **Fixed function prototypes in `extern.h`**:
|
||||
- `void fatal();` → `void fatal(char *s);`
|
||||
- `void my_exit();` → `void my_exit(int st);`
|
||||
- `void set_order();` → `void set_order(int *order, int numthings);`
|
||||
|
||||
2. **Fixed function pointer types**:
|
||||
- `void (*d_func)();` → `void (*d_func)(int);` in `rogue.h` and `daemon.c`
|
||||
- `void (*func)();` → `void (*func)(int);` in `fuse()` and `start_daemon()`
|
||||
- `void (*pa_daemon)();` → `void (*pa_daemon)(int);` in `potions.c`
|
||||
|
||||
3. **Removed conflicting local declaration**:
|
||||
- Removed `struct tm *localtime();` from `rip.c` (conflicts with `<time.h>`)
|
||||
|
||||
4. **Fixed incorrect function call**:
|
||||
- `new_item(sizeof(THING))` → `new_item()` in `state.c` (function doesn't take parameters)
|
||||
|
||||
**Reasoning**:
|
||||
- Modern C standards require proper function prototypes
|
||||
- Function pointers must match their call sites
|
||||
- Local declarations shouldn't conflict with standard library
|
||||
- Functions should be called with correct number of arguments
|
||||
|
||||
**Impact**:
|
||||
- ✅ Eliminates all C23 compatibility warnings
|
||||
- ✅ Build now compiles with zero warnings
|
||||
- ✅ Better type safety and error checking
|
||||
- ✅ No functional changes - all functions work as before
|
||||
|
||||
**Files Changed**:
|
||||
- `extern.h` - function declarations
|
||||
- `rogue.h` - function pointer types in struct and function signatures
|
||||
- `daemon.c` - function pointer parameters
|
||||
- `potions.c` - function pointer in struct
|
||||
- `rip.c` - removed conflicting localtime declaration
|
||||
- `state.c` - fixed incorrect function call
|
||||
|
||||
**Testing**:
|
||||
- [x] Verify build succeeds ✅
|
||||
- [x] Zero compilation warnings ✅
|
||||
- [x] Executable created successfully ✅
|
||||
|
||||
**Status**: ✅ **COMPLETE** - Build now compiles with zero warnings
|
||||
|
||||
---
|
||||
|
||||
## Pending Issues
|
||||
|
||||
Issues identified but not yet fixed:
|
||||
@@ -122,7 +185,7 @@ Issues identified but not yet fixed:
|
||||
- [x] Builds successfully on macOS ✅
|
||||
- [ ] Builds successfully on Linux
|
||||
- [x] No compilation errors ✅
|
||||
- [ ] No compilation warnings (currently 10+ warnings documented above)
|
||||
- [x] No compilation warnings ✅ (All warnings fixed!)
|
||||
|
||||
---
|
||||
|
||||
|
||||
4
daemon.c
4
daemon.c
@@ -63,7 +63,7 @@ find_slot(void (*func)())
|
||||
* Start a daemon, takes a function.
|
||||
*/
|
||||
void
|
||||
start_daemon(void (*func)(), int arg, int type)
|
||||
start_daemon(void (*func)(int), int arg, int type)
|
||||
{
|
||||
register struct delayed_action *dev;
|
||||
|
||||
@@ -117,7 +117,7 @@ do_daemons(int flag)
|
||||
* Start a fuse to go off in a certain number of turns
|
||||
*/
|
||||
void
|
||||
fuse(void (*func)(), int arg, int time, int type)
|
||||
fuse(void (*func)(int), int arg, int time, int type)
|
||||
{
|
||||
register struct delayed_action *wire;
|
||||
|
||||
|
||||
6
extern.h
6
extern.h
@@ -131,11 +131,11 @@ void come_down();
|
||||
void doctor();
|
||||
void end_line();
|
||||
void endit(int sig);
|
||||
void fatal();
|
||||
void fatal(char *s);
|
||||
void getltchars();
|
||||
void land();
|
||||
void leave(int);
|
||||
void my_exit();
|
||||
void my_exit(int st);
|
||||
void nohaste();
|
||||
void playit();
|
||||
void playltchars(void);
|
||||
@@ -144,7 +144,7 @@ void quit(int);
|
||||
void resetltchars(void);
|
||||
void rollwand();
|
||||
void runners();
|
||||
void set_order();
|
||||
void set_order(int *order, int numthings);
|
||||
void sight();
|
||||
void stomach();
|
||||
void swander();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
typedef struct
|
||||
{
|
||||
int pa_flags;
|
||||
void (*pa_daemon)();
|
||||
void (*pa_daemon)(int);
|
||||
int pa_time;
|
||||
char *pa_high, *pa_straight;
|
||||
} PACT;
|
||||
|
||||
1
rip.c
1
rip.c
@@ -230,7 +230,6 @@ death(char monst)
|
||||
char **dp, *killer;
|
||||
struct tm *lt;
|
||||
static time_t date;
|
||||
struct tm *localtime();
|
||||
|
||||
signal(SIGINT, SIG_IGN);
|
||||
purse -= purse / 10;
|
||||
|
||||
6
rogue.h
6
rogue.h
@@ -567,7 +567,7 @@ char floor_at();
|
||||
void flush_type();
|
||||
int fight(coord *mp, THING *weap, bool thrown);
|
||||
void fix_stick(THING *cur);
|
||||
void fuse(void (*func)(), int arg, int time, int type);
|
||||
void fuse(void (*func)(int), int arg, int time, int type);
|
||||
bool get_dir();
|
||||
int gethand();
|
||||
void give_pack(THING *tp);
|
||||
@@ -651,7 +651,7 @@ void show_map();
|
||||
void show_win(char *message);
|
||||
int sign(int nm);
|
||||
int spread(int nm);
|
||||
void start_daemon(void (*func)(), int arg, int type);
|
||||
void start_daemon(void (*func)(int), int arg, int type);
|
||||
void start_score();
|
||||
void status();
|
||||
int step_ok(int ch);
|
||||
@@ -729,7 +729,7 @@ struct room *roomin(coord *cp);
|
||||
|
||||
extern struct delayed_action {
|
||||
int d_type;
|
||||
void (*d_func)();
|
||||
void (*d_func)(int);
|
||||
int d_arg;
|
||||
int d_time;
|
||||
} d_list[MAXDAEMONS];
|
||||
|
||||
Reference in New Issue
Block a user