Source:NetHack 5.0.0/include/tradstdc.h
Jump to navigation
Jump to search
Below is the full text to tradstdc.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/tradstdc.h#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 5.0 tradstdc.h $NHDT-Date: 1744938651 2025/04/17 17:10:51 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.67 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2006. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #ifndef TRADSTDC_H 7. #define TRADSTDC_H 8. 9. #if defined(DUMB) && !defined(NOVOID) 10. #define NOVOID 11. #endif 12. 13. #ifdef NOVOID 14. #define void int 15. #endif 16. 17. /* 18. * Borland C provides enough ANSI C compatibility in its Borland C++ 19. * mode to warrant this. But it does not set __STDC__ unless it compiles 20. * in its ANSI keywords only mode, which prevents use of <dos.h> and 21. * far pointer use. 22. */ 23. #if (defined(__STDC__) || defined(__TURBOC__)) && !defined(NOTSTDC) 24. #define NHSTDC 25. #endif 26. 27. #if defined(ultrix) && defined(__STDC__) && !defined(__LANGUAGE_C) 28. /* Ultrix seems to be in a constant state of flux. This check attempts to 29. * set up ansi compatibility if it wasn't set up correctly by the compiler. 30. */ 31. #ifdef mips 32. #define __mips mips 33. #endif 34. #ifdef LANGUAGE_C 35. #define __LANGUAGE_C LANGUAGE_C 36. #endif 37. #endif 38. 39. /* 40. * ANSI X3J11 detection. 41. * Makes substitutes for compatibility with the old C standard. 42. */ 43. 44. /* Decide how to handle variable parameter lists: 45. * USE_STDARG means use the ANSI <stdarg.h> facilities (only ANSI compilers 46. * should do this, and only if the library supports it). 47. * USE_VARARGS means use the <varargs.h> facilities. Again, this should only 48. * be done if the library supports it. ANSI is *not* required for this. 49. * Otherwise, the kludgy old methods are used. 50. */ 51. 52. /* #define USE_VARARGS */ /* use <varargs.h> instead of <stdarg.h> */ 53. /* #define USE_OLDARGS */ /* don't use any variable argument facilities */ 54. 55. #if defined(apollo) /* Apollos have stdarg(3) but not stdarg.h */ 56. #define USE_VARARGS 57. #endif 58. 59. #if !defined(USE_STDARG) && !defined(USE_VARARGS) && !defined(USE_OLDARGS) 60. /* the old VARARGS and OLDARGS stuff is still here, but since we're 61. requiring C99 these days it's unlikely to be useful */ 62. #define USE_STDARG 63. #endif 64. 65. #ifdef NEED_VARARGS /* only define these if necessary */ 66. /* 67. * These changed in 3.6.0. VA_END() provides a hidden 68. * closing brace to complement VA_DECL()'s hidden opening brace, so code 69. * started with VA_DECL() needs an extra opening brace to complement 70. * the explicit final closing brace. This was done so that the source 71. * would look less strange, where VA_DECL() appeared to introduce a 72. * function whose opening brace was missing; there are now visible and 73. * invisible braces at beginning and end. Sample usage: 74. void foo VA_DECL(int, arg) --macro expansion has a hidden opening brace 75. { --explicit opening brace (actually introduces a nested block) 76. VA_START(bar); 77. ...code for foo... 78. VA_END(); --expansion provides a closing brace for the nested block 79. } --closing brace, pairs with the hidden one in VA_DECL() 80. * Reading the code--or using source browsing tools which match braces-- 81. * results in seeing a matched set of braces. Usage of VA_END() is 82. * potentially trickier, but nethack uses it in a straightforward manner. 83. */ 84. 85. #ifdef USE_STDARG 86. #include <stdarg.h> 87. #define VA_DECL(typ1, var1) \ 88. (typ1 var1, ...) \ 89. { \ 90. va_list the_args; 91. #define VA_DECL2(typ1, var1, typ2, var2) \ 92. (typ1 var1, typ2 var2, ...) \ 93. { \ 94. va_list the_args; 95. #define VA_INIT(var1, typ1) 96. #define VA_NEXT(var1, typ1) (var1 = va_arg(the_args, typ1)) 97. #define VA_ARGS the_args 98. #define VA_START(x) va_start(the_args, x) 99. #define VA_END() \ 100. va_end(the_args); \ 101. } 102. #define VA_PASS1(a1) a1 103. #if defined(ULTRIX_PROTO) && !defined(_VA_LIST_) 104. #define _VA_LIST_ /* prevents multiple def in stdio.h */ 105. #endif 106. #else 107. 108. #ifdef USE_VARARGS 109. #include <varargs.h> 110. #define VA_DECL(typ1, var1) \ 111. (va_alist) va_dcl \ 112. { \ 113. va_list the_args; \ 114. typ1 var1; 115. #define VA_DECL2(typ1, var1, typ2, var2) \ 116. (va_alist) va_dcl \ 117. { \ 118. va_list the_args; \ 119. typ1 var1; \ 120. typ2 var2; 121. #define VA_ARGS the_args 122. #define VA_START(x) va_start(the_args) 123. #define VA_INIT(var1, typ1) var1 = va_arg(the_args, typ1) 124. #define VA_NEXT(var1, typ1) (var1 = va_arg(the_args, typ1)) 125. #define VA_END() \ 126. va_end(the_args); \ 127. } 128. #define VA_PASS1(a1) a1 129. #else 130. 131. /*USE_OLDARGS*/ 132. /* 133. * CAVEAT: passing double (including float promoted to double) will 134. * almost certainly break this, as would any integer type bigger than 135. * sizeof (char *). 136. * NetHack avoids floating point, and any configuration able to use 137. * 'long long int' or I64P32 or the like should be using USE_STDARG. 138. */ 139. #ifndef VA_TYPE 140. typedef const char *vA; 141. #define VA_TYPE 142. #endif 143. #define VA_ARGS arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 144. #define VA_DECL(typ1, var1) \ 145. (var1, VA_ARGS) typ1 var1; vA VA_ARGS; \ 146. { 147. #define VA_DECL2(typ1, var1, typ2, var2) \ 148. (var1, var2, VA_ARGS) typ1 var1; typ2 var2; vA VA_ARGS; \ 149. { 150. #define VA_START(x) 151. #define VA_INIT(var1, typ1) 152. /* This is inherently risky, and should only be attempted as a 153. very last resort; manipulating arguments which haven't actually 154. been passed may or may not cause severe trouble depending on 155. the function-calling/argument-passing mechanism being used. 156. 157. [nethack's core doesn't use VA_NEXT() so doesn't use VA_SHIFT() 158. either, and this definition is just retained for completeness. 159. lev_comp does use VA_NEXT(), but it passes all 'argX' arguments. 160. Note: as of 5.0.0, lev_comp doesn't exist anymore.] 161. */ 162. #define VA_SHIFT() \ 163. (arg1 = arg2, arg2 = arg3, arg3 = arg4, arg4 = arg5, arg5 = arg6, \ 164. arg6 = arg7, arg7 = arg8, arg8 = arg9, arg9 = 0) 165. #define VA_NEXT(var1, typ1) ((var1 = (typ1) arg1), VA_SHIFT(), var1) 166. #define VA_END() } 167. /* needed in pline.c, where full number of arguments is known and expected */ 168. #define VA_PASS1(a1) \ 169. (vA) a1, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0 170. #endif 171. #endif 172. 173. #endif /* NEED_VARARGS */ 174. 175. /* generic pointer, always a macro; genericptr_t is usually a typedef */ 176. #define genericptr void * 177. #ifndef genericptr_t 178. typedef genericptr genericptr_t; /* (void *) or (char *) */ 179. #endif 180. 181. #ifndef NO_PTR_FMT 182. /* We actually want to know which systems have an ANSI run-time library 183. * to know which support the %p format for printing pointers. 184. * Since we require C99 or later, assume the library supports it. */ 185. #define HAS_PTR_FMT 186. #endif 187. 188. /* 189. * According to ANSI C, prototypes for old-style function definitions like 190. * int func(arg) short arg; { ... } 191. * must specify widened arguments (char and short to int, float to double), 192. * int func(int); 193. * same as how narrow arguments get passed when there is no prototype info. 194. * However, various compilers accept shorter arguments (char, short, etc.) 195. * in prototypes and do typechecking with them. Therefore this mess to 196. * allow the better typechecking while also allowing some prototypes for 197. * the ANSI compilers so people quit trying to fix the prototypes to match 198. * the standard and thus lose the typechecking. 199. */ 200. #if defined(MSDOS) && !defined(__GO32__) 201. #define UNWIDENED_PROTOTYPES 202. #endif 203. #if defined(AMIGA) && !defined(AZTEC_50) 204. #define UNWIDENED_PROTOTYPES 205. #endif 206. #if defined(macintosh) && (defined(__SC__) || defined(__MRC__)) 207. #define WIDENED_PROTOTYPES 208. #endif 209. #if defined(__MWERKS__) && defined(__BEOS__) 210. #define UNWIDENED_PROTOTYPES 211. #endif 212. #if defined(WIN32) 213. #define UNWIDENED_PROTOTYPES 214. #endif 215. 216. #if defined(ULTRIX_PROTO) && defined(ULTRIX_CC20) 217. #define UNWIDENED_PROTOTYPES 218. #endif 219. #if defined(apollo) 220. #define UNWIDENED_PROTOTYPES 221. #endif 222. 223. #ifndef UNWIDENED_PROTOTYPES 224. #if defined(NHSTDC) || defined(ULTRIX_PROTO) || defined(THINK_C) 225. #ifndef WIDENED_PROTOTYPES 226. #define WIDENED_PROTOTYPES 227. #endif 228. #endif 229. #endif 230. 231. /* this applies to both VMS and Digital Unix/HP Tru64 */ 232. #ifdef WIDENED_PROTOTYPES 233. /* ANSI C uses "value preserving rules", where 'unsigned char' and 234. 'unsigned short' promote to 'int' if signed int is big enough to hold 235. all possible values, rather than traditional "sign preserving rules" 236. where 'unsigned char' and 'unsigned short' promote to 'unsigned int'. 237. However, the ANSI C rules aren't binding on non-ANSI compilers. 238. When DEC C (aka Compaq C, then HP C) is in non-standard 'common' mode 239. it supports prototypes that expect widened types, but it uses the old 240. sign preserving rules for how to widen narrow unsigned types. (In its 241. default 'relaxed' mode, __STDC__ is 1 and uchar widens to 'int'.) */ 242. #if defined(__DECC) && (!defined(__STDC__) || !__STDC__) 243. #define UCHAR_P unsigned int 244. #endif 245. #endif 246. 247. /* These are used for arguments within VDECL prototype declarations. 248. */ 249. #ifdef UNWIDENED_PROTOTYPES 250. #define CHAR_P char 251. #define SCHAR_P schar 252. #define UCHAR_P uchar 253. #define XCHAR_P coordxy 254. #define SHORT_P short 255. #ifndef SKIP_BOOLEAN 256. #define BOOLEAN_P boolean 257. #endif 258. #define ALIGNTYP_P aligntyp 259. #else 260. #ifdef WIDENED_PROTOTYPES 261. #define CHAR_P int 262. #define SCHAR_P int 263. #ifndef UCHAR_P 264. #define UCHAR_P int 265. #endif 266. #define XCHAR_P int 267. #define SHORT_P int 268. #define BOOLEAN_P int 269. #define ALIGNTYP_P int 270. #else 271. /* Neither widened nor unwidened prototypes. Argument list expansion 272. * by VDECL always empty; all xxx_P vanish so defs aren't needed. */ 273. #endif 274. #endif 275. 276. /* OBJ_P and MONST_P should _only_ be used for declaring function pointers. 277. */ 278. #if defined(ULTRIX_PROTO) && !defined(__STDC__) 279. /* The ultrix 2.0 and 2.1 compilers (on Ultrix 4.0 and 4.2 respectively) can't 280. * handle "struct obj *" constructs in prototypes. Their bugs are different, 281. * but both seem to work if we put "void*" in the prototype instead. This 282. * gives us minimal prototype checking but avoids the compiler bugs. 283. */ 284. #define OBJ_P void * 285. #define MONST_P void * 286. #else 287. #define OBJ_P struct obj * 288. #define MONST_P struct monst * 289. #endif 290. 291. #if 0 292. /* The problem below is still the case through 4.0.5F, but the suggested 293. * compiler flags in the Makefiles suppress the nasty messages, so we don't 294. * need to be quite so drastic. 295. */ 296. #if defined(__sgi) && !defined(__GNUC__) 297. /* 298. * As of IRIX 4.0.1, /bin/cc claims to be an ANSI compiler, but it thinks 299. * it's impossible for a prototype to match an old-style definition with 300. * unwidened argument types. Thus, we have to turn off all NetHack 301. * prototypes, and avoid declaring several system functions, since the system 302. * include files have prototypes and the compiler also complains that 303. * prototyped and unprototyped declarations don't match. 304. */ 305. #undef VDECL 306. #define VDECL(f, p) f() 307. #endif 308. #endif 309. 310. /* MetaWare High-C defaults to unsigned chars */ 311. /* AIX 3.2 needs this also */ 312. #if defined(__HC__) || defined(_AIX32) 313. #undef signed 314. #endif 315. 316. /* 317. * Language 318. * Standard 319. * 320. * NetHack 5.0 range 321. * / 322. * / 323. * C2y X NetHack 3.6 and earlier range 324. * C23 X / 325. * C17 X X 326. * C11 X X 327. * C99 X X 328. * C89 X 329. * 330. * 331. * The NetHack 5.0 source code currently makes use of the following 332. * C99 (and above) language features: 333. * 334. * commas at the end of enumerator lists 335. * variable declarations in for loop initializers 336. * mixing declarations and code 337. * variadic macros 338. * 'long long' 339. * 340. * The NetHack 5.0 source code adheres to the following greater-than C99 341. * language restrictions: 342. * 343. * Removal of K&R function definitions 344. * Removal of implicit int 345. */ 346. 347. /* 348. * Provide a shorthand way of checking for a certain C standard 349. * in the NetHack header files by always setting NH_C to one 350. * of three possible values (as of January 2025): 351. * 352. * NH_C >= 202300L Being compiled under C23 or greater 353. * NH_C >= 199900L Being compiled under C99 or greater 354. * NH_C >= 198900L Being compiled under C89 or greater, 355. * or C std could not be determined. 356. */ 357. #if defined(__STDC_VERSION__) 358. #if (__STDC_VERSION__ >= 202000L) 359. #define NH_C 202300L 360. #else 361. #define NH_C 199900L 362. #endif /* C23 or C99 */ 363. #else /* __STDC_VERSION not defined */ 364. #define NH_C 198900L 365. #endif /* __STDC_VERSION not defined */ 366. #ifndef NH_C 367. #define NH_C 198900L 368. #endif 369. 370. /* NH_C is now defined to 198900L or 199900L or 202300L */ 371. 372. #if NH_C >= 202300L 373. /* Give first priority to standard */ 374. #ifndef __has_c_attribute 375. #define __has_c_attribute(x) 0 376. #endif 377. /* 378. * noreturn 379. */ 380. #ifndef ATTRNORETURN 381. #define ATTRNORETURN noreturn 382. /* #warning noreturn from C23 */ 383. #endif /* ATTRNORETURN not defined */ 384. /* 385. * fallthrough 386. */ 387. #if __has_c_attribute(fallthrough) 388. /* Standard attribute is available, use it. */ 389. #define FALLTHROUGH fallthrough 390. /* #warning fallthrough from C23 */ 391. #endif /* __has_c_attribute(fallthrough) */ 392. /* 393. * maybe_unused 394. */ 395. #if __has_c_attribute(maybe_unused) 396. #ifndef ATTRUNUSED 397. #define ATTRUNUSED maybe_unused 398. #endif 399. #endif /* __has_c_attribute(maybe_unused) */ 400. #endif /* NH_C >= 202300L */ 401. 402. /* 403. * Compiler-specific 404. */ 405. 406. #ifdef __clang__ 407. /* clang's gcc emulation is sufficient for nethack's usage */ 408. #ifndef __GNUC__ 409. #define __GNUC__ 5 /* high enough for returns_nonnull */ 410. #endif 411. #endif 412. 413. /* 414. * gcc (and also clang which masquerades as__GNUC__==5 due to #define above) 415. * 416. * Allow gcc2 and above to check parameters of printf-like calls with 417. * -Wformat; append this to a prototype declaration (see pline() in extern.h). 418. */ 419. #ifdef __GNUC__ 420. #if (__GNUC__ >= 2) && !defined(USE_OLDARGS) 421. #define PRINTF_F(f, v) __attribute__((format(printf, f, v))) 422. #endif 423. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) 424. #define PRINTF_F_PTR(f, v) PRINTF_F(f, v) 425. #endif 426. #if __GNUC__ >= 3 427. #ifndef ATTRUNUSED 428. #define UNUSED __attribute__((unused)) 429. #endif 430. #ifndef ATTRNORETURN 431. #ifndef NORETURN 432. #define NORETURN __attribute__((noreturn)) 433. /* #warning NORETURN __attribute__((noreturn)) from __GNUC__ >= 3 */ 434. #endif /* NORETURN */ 435. #endif /* ATTRNORETURN */ 436. #endif /* __GNUC__ >= 3 */ 437. #if __GNUC__ >= 5 438. #ifndef NONNULLS_DEFINED 439. #define DO_DEFINE_NONNULLS 440. #endif /* !NONNULLS_DEFINED */ 441. /* #pragma message is available */ 442. #define NH_PRAGMA_MESSAGE 1 443. #endif /* __GNUC__ greater than or equal to 5 */ 444. #if (!defined(__linux__) && !defined(MACOS)) || defined(GCC_URWARN) 445. /* disable gcc's __attribute__((__warn_unused_result__)) since explicitly 446. discarding the result by casting to (void) is not accepted as a 'use' */ 447. #define __warn_unused_result__ /*empty*/ 448. #define warn_unused_result /*empty*/ 449. #endif /* GCC_URWARN || !__linux || !MACOS */ 450. #endif /* __GNUC__ || clang masquerading as __GNUC__==5 */ 451. 452. /* 453. * clang-specific 454. * 455. */ 456. #if defined(__clang__) 457. #ifndef FALLTHROUGH 458. #if defined(__clang_major__) 459. #if __clang_major__ >= 9 460. #define FALLTHROUGH __attribute__((fallthrough)) 461. /* #warning FALLTHROUGH __attribute__((fallthrough)) from clang */ 462. #endif /* __clang_major__ greater than or equal to 9 */ 463. #endif /* __clang_major__ is defined */ 464. #endif /* FALLTHROUGH */ 465. #if !defined(DO_DEFINE_NONNULLS) 466. #define DO_DEFINE_NONNULLS 467. #endif 468. #endif /* __clang__ */ 469. 470. /* 471. * NONNULL args 472. */ 473. #if defined(DO_DEFINE_NONNULLS) && !defined(NONNULLS_DEFINED) 474. #define NONNULL __attribute__((returns_nonnull)) 475. #define NONNULLPTRS __attribute__((nonnull)) 476. #define NONNULLARG1 __attribute__((nonnull (1))) 477. #define NONNULLARG2 __attribute__((nonnull (2))) 478. #define NONNULLARG3 __attribute__((nonnull (3))) 479. #define NONNULLARG4 __attribute__((nonnull (4))) 480. #define NONNULLARG5 __attribute__((nonnull (5))) 481. #define NONNULLARG6 __attribute__((nonnull (6))) 482. #define NONNULLARG7 __attribute__((nonnull (7))) /* for bhit() */ 483. #define NONNULLARG12 __attribute__((nonnull (1, 2))) 484. #define NONNULLARG23 __attribute__((nonnull (2, 3))) 485. #define NONNULLARG123 __attribute__((nonnull (1, 2, 3))) 486. #define NONNULLARG13 __attribute__((nonnull (1, 3))) 487. #define NONNULLARG14 __attribute__((nonnull (1, 4))) /* for query_category */ 488. #define NONNULLARG134 __attribute__((nonnull (1, 3, 4))) /* for do_stone_mon */ 489. #define NONNULLARG145 __attribute__((nonnull (1, 4, 5))) /* find_roll_to_hit */ 490. #define NONNULLARG17 __attribute__((nonnull (1, 7))) /* for askchain() */ 491. #define NONNULLARG24 __attribute__((nonnull (2, 4))) /* query_objlist() */ 492. #define NONNULLARG45 __attribute__((nonnull (4, 5))) /* do_screen_descri... */ 493. #define NONNULLS_DEFINED 494. #undef DO_DEFINE_NONNULLS 495. #endif /* DO_DEFINE_NONNULLS && !NONNULLS_DEFINED */ 496. 497. /* 498. * Microsoft compiler 499. */ 500. #ifdef _MSC_VER 501. #ifndef ATTRNORETURN 502. #define ATTRNORETURN __declspec(noreturn) 503. /* #warning ATTRNORETURN __declspec(noreturn) from _MSC_VER */ 504. #endif 505. /* #pragma message is available */ 506. #define NH_PRAGMA_MESSAGE 1 507. #endif /* _MSC_VER */ 508. 509. #if !defined(UNUSED) && defined(ATTRUNUSED) 510. #define UNUSED ATTRUNUSED 511. #endif 512. 513. /* Fallback implementations */ 514. #ifndef PRINTF_F 515. #define PRINTF_F(f, v) 516. #endif 517. #ifndef PRINTF_F_PTR 518. #define PRINTF_F_PTR(f, v) 519. #endif 520. #ifndef UNUSED 521. #define UNUSED 522. #endif 523. #ifndef ATTRUNUSED 524. #define ATTRUNUSED 525. #endif 526. #ifndef FALLTHROUGH 527. #define FALLTHROUGH 528. #endif 529. #ifndef ATTRNORETURN 530. #define ATTRNORETURN 531. #endif 532. #ifndef NORETURN 533. #define NORETURN 534. #endif 535. #ifndef NONNULLS_DEFINED 536. #define NONNULL 537. #define NONNULLPTRS 538. #define NONNULLARG1 539. #define NONNULLARG2 540. #define NONNULLARG3 541. #define NONNULLARG4 542. #define NONNULLARG5 543. #define NONNULLARG6 544. #define NONNULLARG7 545. #define NONNULLARG12 546. #define NONNULLARG23 547. #define NONNULLARG123 548. #define NONNULLARG13 549. #define NONNULLARG14 550. #define NONNULLARG134 551. #define NONNULLARG145 552. #define NONNULLARG17 553. #define NONNULLARG24 554. #define NONNULLARG45 555. #define NONNULLS_DEFINED 556. #endif /* NONNULLS_DEFINED */ 557. #ifndef NO_NNARGS 558. #define NO_NNARGS /*empty*/ 559. #endif /* NO_NNARGS */ 560. 561. /* 562. * Allow gcc and clang to catch the use of non-C99 functions that 563. * NetHack has replaced with a C99 standard function. The old non-C99 564. * function will cause a link failure on non-Unix platforms, 565. * so it is preferrable to catch it early, during compile. 566. */ 567. #if !defined(X11_BUILD) && !defined(__cplusplus) 568. #if defined(__GNUC__) && !defined(__clang__) 569. #if __GNUC__ >= 12 570. extern char *index(const char *s, int c) __attribute__ ((unavailable)); 571. extern char *rindex(const char *s, int c) __attribute__ ((unavailable)); 572. #endif 573. #endif 574. #if defined(__clang__) 575. #if __clang_major__ >= 7 576. extern char *index(const char *s, int c) __attribute__ ((unavailable)); 577. extern char *rindex(const char *s, int c) __attribute__ ((unavailable)); 578. #endif 579. #endif 580. #endif 581. 582. 583. #endif /* TRADSTDC_H */