c89

Using the scanf function in while loop

烈酒焚心 提交于 2019-11-26 22:05:46
问题 I am attempting to format a space-delimited user input for a programming assignment. Essentially, the input consists of an arbitrary number of expressions L integer integer integer integer and C integer integer integer . For example: L 1 1 5 7 C 4 5 3 . So far, I've managed to extract the integers depending on the initial character, and can iterate through the string using the scanf function: char a; while(scanf("%c", &a) == 1){ if(a == 'C'){ int inputX, inputY, inputR; scanf("%d %d %d",

Using M_PI with C89 standard

你离开我真会死。 提交于 2019-11-26 20:57:50
I'm using C and trying to get access to the constant M_PI (3.14159...). I have imported the math.h header file, but the M_PI constant was still undefined. Through some searching on StackOverflow I have found that I need to add #define _USE_MATH_DEFINES to my code (see example code below). This works fine when compiling normally, but I need to be able to compile with the std=c89 flag for the work that I'm doing. How should I access M_PI from some C89 code? A conforming standard library file math.h is not only not required to, but actually must not define M_PI by default. In this context 'by

What's the difference between “int” and “int_fast16_t”?

夙愿已清 提交于 2019-11-26 20:19:19
问题 As I understand it, the C specification says that type int is supposed to be the most efficient type on target platform that contains at least 16 bits. Isn't that exactly what the C99 definition of int_fast16_t is too? Maybe they put it in there just for consistency, since the other int_fastXX_t are needed? Update To summarize discussion below: My question was wrong in many ways. The C standard does not specify bitness for int . It gives a range [-32767,32767] that it must contain. I realize

Trying to tweak sscanf() to ignore \n and \t [duplicate]

随声附和 提交于 2019-11-26 18:38:02
问题 This question already has an answer here: C: How can I make it so scanf() input has one of two formats? 2 answers I'm developing a triangle calculation and trying to tweak my sscanf to ignore spaces, newlines \n and tabs \t . How can I do that? I have: if(sscanf(str, "{ [ %lf ; %lf ] , [ %lf ; %lf ] , [ %lf ; %lf ] }", &x_1, &y_1, &x_2, &y_2, &x_3, &y_3) == 6) which perfectly works for inputs like these: 1) {[0;0],[19;10],[0;10]} 2) { [ 0 ; 0], [12;0],[0 ;10] } but it doesn't work for

Does either ANSI C or ISO C specify what -5 % 10 should be?

那年仲夏 提交于 2019-11-26 16:34:42
I seem to remember that ANSI C didn't specify what value should be returned when either operand of a modulo operator is negative (just that it should be consistent). Did it get specified later, or was it always specified and I am remembering incorrectly? C89, not totally (§3.3.5/6). It can be either -5 or 5, because -5 / 10 can return 0 or -1 ( % is defined in terms of a linear equation involving / , * and + ): When integers are divided and the division is inexact, if both operands are positive the result of the / operator is the largest integer less than the algebraic quotient and the result

Why was mixing declarations and code forbidden up until C99?

帅比萌擦擦* 提交于 2019-11-26 12:44:23
问题 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

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

末鹿安然 提交于 2019-11-26 11:48:08
问题 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

C variable declarations after function heading in definition [duplicate]

流过昼夜 提交于 2019-11-26 11:39:23
问题 This question already has answers here : What is this strange function definition syntax in C? [duplicate] (6 answers) Closed 5 years ago . When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations that followed the \"function heading\" in the definition. Is this valid in ISO C (C99)? when should this be done in production code instead of just declaring the variables within the \"function heading?\" Why is it being done here? I refer to the function

Enabling VLAs (variable length arrays) in MS Visual C++?

戏子无情 提交于 2019-11-26 10:42:57
How can i enable the use of VLAs, variable length arrays as defined in C99, in MS Visual C++ or that is not possible at all? Yes i know that the C++ standard is based on C89 and that VLAs are not available in C89 standard and thus aren't available in C++, but MSVC++ is supposed to to be a C compiler also, a behavior that can be switched on using the /TC compiler parameter ( Compile as C Code (/TC) ). But doing so does not seem to enable VLAs and the compiling process fails with the same errors when building as C++( Compile as C++ Code (/TP) ). Maybe MSVC++ C compiler is C89 compliant only or i

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

佐手、 提交于 2019-11-26 09:35:18
问题 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