c89

Are prototypes required for all functions in C89, C90 or C99?

家住魔仙堡 提交于 2019-12-27 09:01:57
问题 To be truly standards-compliant, must all functions in C (except for main) have a prototype, even if they are only used after their definition in the same translation unit? 回答1: It depends on what you mean by 'truly standards compliant'. However, the short answer is "it is a good idea to ensure that all functions have a prototype in scope before being used". A more qualified answer notes that if the function accepts variable arguments (notably the printf() family of functions), then a

Are prototypes required for all functions in C89, C90 or C99?

为君一笑 提交于 2019-12-27 09:01:19
问题 To be truly standards-compliant, must all functions in C (except for main) have a prototype, even if they are only used after their definition in the same translation unit? 回答1: It depends on what you mean by 'truly standards compliant'. However, the short answer is "it is a good idea to ensure that all functions have a prototype in scope before being used". A more qualified answer notes that if the function accepts variable arguments (notably the printf() family of functions), then a

Are prototypes required for all functions in C89, C90 or C99?

北战南征 提交于 2019-12-27 09:01:06
问题 To be truly standards-compliant, must all functions in C (except for main) have a prototype, even if they are only used after their definition in the same translation unit? 回答1: It depends on what you mean by 'truly standards compliant'. However, the short answer is "it is a good idea to ensure that all functions have a prototype in scope before being used". A more qualified answer notes that if the function accepts variable arguments (notably the printf() family of functions), then a

NULL pointer as marker of end of array

大憨熊 提交于 2019-12-24 11:34:02
问题 I read the 6.3th paragraph of the "C programming language" second edition, by Kernigan & Ritchie. Some structure: struct key { char *word; int count; } keytab[NKEYS] { { "auto", 0 }, { "break", 0 }, { "case", 0 }, { "char", 0 }, { "const", 0 }, { "continue", 0 } }; Authors wrote about it: The quantity NKEYS is the number of keywords in keytab. Although we could count this by hand, it’s a lot easier and safer to do it by machine, especially if the list is subject to change. One possibility

Struct pointer casts

天涯浪子 提交于 2019-12-24 04:32:12
问题 I'm trying to implement a linked list like this: typedef struct SLnode { void* item; void* next; } SLnode; typedef struct DLnode { void* item; void* next; struct DLnode* prev; } DLnode; typedef struct LinkedList { void* head; /*SLnode if doubly_linked is false, otherwise DLnode*/ void* tail; /* here too */ bool doubly_linked; } LinkedList; And I want to access it like this: void* llnode_at(const LinkedList* ll, size_t index) { size_t i; SLnode* current; current = ll->head; for(i = 0; i <

Struct pointer casts

风格不统一 提交于 2019-12-24 04:32:01
问题 I'm trying to implement a linked list like this: typedef struct SLnode { void* item; void* next; } SLnode; typedef struct DLnode { void* item; void* next; struct DLnode* prev; } DLnode; typedef struct LinkedList { void* head; /*SLnode if doubly_linked is false, otherwise DLnode*/ void* tail; /* here too */ bool doubly_linked; } LinkedList; And I want to access it like this: void* llnode_at(const LinkedList* ll, size_t index) { size_t i; SLnode* current; current = ll->head; for(i = 0; i <

default argument promotions in the case of inplicit function declarations

穿精又带淫゛_ 提交于 2019-12-23 04:22:50
问题 I've tried to search in old questions but I've not solved my problem. I try to explain my doubt; Supposing to work in c89 mode, if there's not a prototype of the function before the function call, there is an implicit declaration of the function, the type of the function is int and the arguments are converted through Default Argument Promotions: the objects of type char or short int (whether signed or not) are promoted to either int or unsigned int, as appropriate; and that objects of type

Macro for use in expression while enforcing its arguments to be compile time constants

試著忘記壹切 提交于 2019-12-23 01:44:11
问题 I am looking for a way to #define a macro that enforces its arguments to be compile time constants, and at the same time can be used in an expression. The method should be working under C90 and be upward compatible - if possible also portable for the different C++ variants. Also a 0-footprint to memory is preferable. Consider a compile-time minimum macro as an example. The behavior should be: #define CT_MIN(CTC_A, CTC B) <<<MAGIC>>> int a = 1; int b = a + CT_MIN(1,4); /* OK */ int c = a + CT

Safe Floating Point Division

允我心安 提交于 2019-12-22 11:38:11
问题 I have some places in my code where I want to assure that a division of 2 arbitrary floating point numbers (32 bit single precision) won't overflow. The target/compiler does not guarantee (explicitly enough) nice handling of -INF/INF and (does not fully guarantees IEEE 754 for the exceptional values - (possibly undefined) - and target might change). Also I cannot make save assumtions on the inputs for this few special places and I am bound to C90 standard libraries. I have read What Every

Are there any well-established/standardized ways to use fixed-width integers in C89?

断了今生、忘了曾经 提交于 2019-12-22 05:46:06
问题 Some background : the header stdint.h is part of the C standard since C99. It includes typedefs that are ensured to be 8, 16, 32, and 64-bit long integers, both signed and unsigned. This header is not part of the C89 standard, though, and I haven't yet found any straightforward way to ensure that my datatypes have a known length. Getting to the actual topic The following code is how SQLite (written in C89) defines 64-bit integers, but I don't find it convincing. That is, I don't think it's