ansi-c

-Wsequence-point warning - what does it mean and does it violate ANSI C standard?

℡╲_俬逩灬. 提交于 2020-02-22 06:11:21
问题 In line tab[i] = tab[i+1] - tab[i] + (tab[i+1] = tab[i]); I have a warning [Warning] operation on '*(tab + ((sizetype)i + 1u) * 4u)' may be undefined [-Wsequence-point] I want to swap these two integer arrays elements without temporary variable and without violation of ANSI C. Program still works, but is it ok? 回答1: Your code relies on behaviour that is not covered by the standard. So your code may behave differently on different compilers, different versions of the same compiler and even

pow(1,0) returns 0? [closed]

三世轮回 提交于 2019-12-31 04:42:06
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Why does this: printf("%d\n", pow(1,0)); /* outputs 0 */ returns 0 ? I expected it to return 1 . 回答1: pow() returns a double type. You need to use %f format specifier to print a double . Using inappropriate format specifier for the supplied argument type causes undefined behaviour. Check chapter §7.21.6.1 of the

Who defines C operator precedence and associativity?

心不动则不痛 提交于 2019-12-28 05:27:05
问题 Introduction In every textbook on C/C++, you'll find an operator precedence and associativity table such as the following: http://en.cppreference.com/w/cpp/language/operator_precedence One of the questions on StackOverflow asked something like this: What order do the following functions execute: f1() * f2() + f3(); f1() + f2() * f3(); Referring to the previous chart I confidently replied that functions have left-to-right associativity so in the previous statements the are evaluated like this

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

Multi-Dimensional Arrays in C: are they jagged?

假装没事ソ 提交于 2019-12-21 03:20:09
问题 A simple question about the C programming language (ANSI-C): Are the multi-dimensional arrays in C jagged? I mean - are we talking about "array of arrays" (one array of pointers to other addresses in the memory) , or this is just "long one-dimensional array" (which is stored sequentially in the memory)? What that bothers me is that I'm kinda sure that: matrix[i][j] is equivalent to * ( * (matrix + i) + j) 回答1: A multidimensional array in C is contiguous. The following: int m[4][5]; consists

Are there any differences between ANSI C and ISO C?

≡放荡痞女 提交于 2019-12-18 13:12:05
问题 I understand that there is both an ANSI standard and an ISO standard for C. Are there any differences between these two standards? If so, what are they? And if there is not a difference then what's the point of having two standards? 回答1: In 1990, the ANSI C standard (with a few minor modifications) was adopted by the International Organization for Standardization as ISO/IEC 9899:1990. This version is sometimes called C90. Therefore, the terms "C89" and "C90" refer to essentially the same

ANSI C vs other C standards

陌路散爱 提交于 2019-12-18 10:42:48
问题 On several compilers I have used (all gcc but various versions) I get a C99 mode error for things like declaring int i inside the for loop expression instead of before it (if I do not use the std=c99 option). After reading here I understand that the gcc options -ansi , -std=c89 , and -std=iso9899:1990 all evaluate to the ANSI C standard, but I don't understand why/if I should pick the c89 standard versus a newer standard like c99 (which is the newest I assume). Also, I see multiple versions

Inserting strings into another string in C

為{幸葍}努か 提交于 2019-12-13 03:48:55
问题 I'm implementing a function which, given a string, a character and another string (since now we can call it the "substring"); puts the substring everywhere the character is in the string. To explain me better, given these parameters this is what the function should return (pseudocode): func ("aeiou", 'i', "hello") -> aehelloou I'm using some functions from string.h lib. I have tested it with pretty good result: char *somestring= "this$ is a tes$t wawawa$wa"; printf("%s", strcinsert(somestring

Simple Delete File Program in ANSI C for Windows

和自甴很熟 提交于 2019-12-10 22:05:43
问题 Looking for a simple program to a delete a file written in ANSI C. Just as an example how would you delete a file at "C:\test.txt" with C? 回答1: You can delete a file from the OS using the remove() function. Like so: #include <stdio.h> int main(){ if(remove("HELLO.txt") == -1) perror("Error in deleting a file"); return 0; } The remove() function is defined in stdio.h . Here are some docs. 回答2: Use the remove function. I believe it is in "stdio.h" 回答3: remove or unlink remove is declared in