c89

How to find my current compiler's standard, like if it is C90, etc

我的梦境 提交于 2019-11-27 11:11:55
问题 I'm working on a Linux machine. Is there any system command to find the standard followed by the C compiler I'm using? 回答1: This is compiler dependent, I'm supposing you're using GCC. You could check your compiler defined macros using: gcc -dM -E - < /dev/null Check the manual about the flags, specially: __STDC_VERSION__ This macro expands to the C Standard's version number, a long integer constant of the form yyyymmL where yyyy and mm are the year and month of the Standard version. This

Can't get rid of “this decimal constant is unsigned only in ISO C90” warning

Deadly 提交于 2019-11-27 10:50:41
问题 I'm using the FNV hash as a hashing algorithm on my Hash Table implementation but I'm getting the warning in the question title on this line: unsigned hash = 2166136261; I don't understand why this is happening because when I do this: printf("%u\n", UINT_MAX); printf("2166136261\n"); I get this: 4294967295 2166136261 Which seems to be under the limits of my machine... Why do I get the warning and what are my options to get rid of it? 回答1: unsigned hash = 2166136261u; // note the u. You need a

ANSI C (ISO C90): Can scanf read/accept an unsigned char?

六眼飞鱼酱① 提交于 2019-11-27 06:38:46
问题 Simple question: Can scanf read/accept a "small integer" into an unsigned char in ANSI C? example code un_char.c: #include <stdio.h> #include <stdlib.h> int main(void) { unsigned char character; scanf("%hhu", &character); return EXIT_SUCCESS; } Compiled as: $ gcc -Wall -ansi -pedantic -o un_char un_char.c un_char.c: In function ‘main’: un_char.c:8: warning: ISO C90 does not support the ‘hh’ gnu_scanf length modifier hh isn't supported by ISO C90. So what scanf conversion can be used in this

Is there any reason to use C instead of C++ for embedded development?

别说谁变了你拦得住时间么 提交于 2019-11-27 05:57:43
Question I have two compilers on my hardware C++ and C89 I'm thinking about using C++ with classes but without polymorphism (to avoid vtables). The main reasons I’d like to use C++ are: I prefer to use “inline” functions instead of macro definitions. I’d like to use namespaces as I prefixes clutter the code. I see C++ a bit type safer mainly because of templates, and verbose casting. I really like overloaded functions and constructors (used for automatic casting). Do you see any reason to stick with C89 when developing for very limited hardware (4kb of RAM)? Conclusion Thank you for your

How to sum large numbers?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 05:32:58
问题 I am trying to calculate 1 + 1 * 2 + 1 * 2 * 3 + 1 * 2 * 3 * 4 + ... + 1 * 2 * ... * n where n is the user input. It works for values of n up to 12. I want to calculate the sum for n = 13 , n = 14 and n = 15 . How do I do that in C89? As I know, I can use unsigned long long int only in C99 or C11. Input 13, result 2455009817, expected 6749977113 Input 14, result 3733955097, expected 93928268313 Input 15, result 1443297817, expected 1401602636313 My code: #include <stdio.h> #include <stdlib.h>

Why was mixing declarations and code forbidden up until C99?

ぐ巨炮叔叔 提交于 2019-11-27 04:28:04
I have recently become a teaching assistant for a university course which primarily teaches C. The course standardized on C90, mostly due to widespread compiler support. One of the very confusing concepts to C newbies with previous Java experience is the rule that variable declarations and code may not be intermingled within a block (compound statement). This limitation was finally lifted with C99, but I wonder: does anybody know why it was there in the first place? Does it simplify variable scope analysis? Does it allow the programmer to specify at which points of program execution the stack

Forward declare FILE *

流过昼夜 提交于 2019-11-27 02:39:14
问题 How do I forward declare FILE * in C? I normally do this using struct MyType; , but naturally this doesn't appear to be possible. If behaviour differs between C standards or compilers and with C++, this is also of interest. Update0 Why I want to do this aside: What I'm asking is how to forward declare a non-struct/"typedef'd struct" type so that I can declare pointers to it. Obviously using void * and casting it in the source file is a bit hackish. 回答1: You can't. The standard just states

Casting an int pointer to a char ptr and vice versa

笑着哭i 提交于 2019-11-27 01:53:06
问题 The problem is simple. As I understand, GCC maintains that chars will be byte-aligned and ints 4-byte-aligned in a 32-bit environment. I am also aware of C99 standard 6.3.2.3 which says that casting between misaligned pointer-types results in undefined operations. What do the other standards of C say about this? There are also many experienced coders here - any view on this will be appreciated. int *iptr1, *iptr2; char *cptr1, *cptr2; iptr1 = (int *) cptr1; cptr2 = (char *) iptr2; 回答1: There

What are the major differences between ANSI C and K&R C?

折月煮酒 提交于 2019-11-27 00:58:56
The Wikipedia article on ANSI C says: One of the aims of the ANSI C standardization process was to produce a superset of K&R C (the first published standard), incorporating many of the unofficial features subsequently introduced. However, the standards committee also included several new features, such as function prototypes (borrowed from the C++ programming language), and a more capable preprocessor. The syntax for parameter declarations was also changed to reflect the C++ style. That makes me think that there are differences. However, I didn't see a comparison between K&R C and ANSI C. Is

Unbuffered I/O in ANSI C

て烟熏妆下的殇ゞ 提交于 2019-11-26 23:36:49
问题 For the sake of education, and programming practice, I'd like to write a simple library that can handle raw keyboard input, and output to the terminal in 'real time'. I'd like to stick with ansi C as much as possible, I just have no idea where to start something like this. I've done several google searches, and 99% of the results use libraries, or are for C++. I'd really like to get it working in windows, then port it to OSX when I have the time. 回答1: Sticking with Standard C as much as