c99

Why is implicit declaration of gets() not allowed in C99?

旧街凉风 提交于 2019-12-12 18:24:48
问题 I am starting to learn programming in C language the book I am refering to code shows some source code with gets() and my IDLE recognises it as well. But still while compiling it, my compiler doesn't agree with it. Can anyone help me out? I am using gets() in the main function and using clang as the compiler. 回答1: Expanding on my comment: First, never use gets() , for any reason, even in toy code. If you see it in an example program, ignore the example and move on. It was deprecated in C99

Reallocating an array (C99)

心已入冬 提交于 2019-12-12 18:15:31
问题 The standard specifies that the contents of reallocated space is undefined if the new size if larger. If preserving the contents of the previously-allocated space is important, is the best way to reallocate data as follows: copying it to the stack, freeing it from the heap, allocating on the heap with more space, and copying back to the heap? Is there another safe way to do this? Would the best way to implement a data structure like a dynamically growing array that only grows be in the form a

GCC doesn't support simple integer constant expression?

牧云@^-^@ 提交于 2019-12-12 12:16:35
问题 GCC 4.9 and 5.1 reject this simple C99 declaration at global scope. Clang accepts it. const int a = 1, b = a; // error: initializer element is not constant How could such a basic feature be missing? It seems very straightforward. 回答1: C99 1 section 6.6 Constant expressions is the controlling section. It states in subsections 6 and 7 : 6/ An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants,

Are C preprocessor statements a part of the C language?

北战南征 提交于 2019-12-12 11:54:43
问题 I recall a claim made by one of my professors in an introductory C course. He stated that the #define preprocessor command enables a programmer to create a constant for use in later code, and that the command was a part of the C language . /* Is this truly C code? */ #define FOO 42 Since this was in an introductory programming class, I suspect that he was merely simplifying the relationship between the source file and the compiler, but nevertheless I wish to verify my understanding. Are

What is the difference between `cc -std=c99` and `c99` on Mac OS?

…衆ロ難τιáo~ 提交于 2019-12-12 08:54:18
问题 Given the following program: /* Find the sum of all the multiples of 3 or 5 below 1000. */ #include <stdio.h> unsigned long int method_one(const unsigned long int n); int main(int argc, char *argv[]) { unsigned long int sum = method_one(1000000000); if (sum != 0) { printf("Sum: %lu\n", sum); } else { printf("Error: Unsigned Integer Wrapping.\n"); } return 0; } unsigned long int method_one(const unsigned long int n) { unsigned long int i; unsigned long int sum = 0; for (i=1; i!=n; ++i) { if (!

Lifetime of temporary objects in C11 vs C99

╄→尐↘猪︶ㄣ 提交于 2019-12-12 07:45:33
问题 I am trying to decipher a note that led to a change between C99 and C11. The change proposed in that note ended up in C11's 6.2.4:8, namely: A non-lvalue expression with structure or union type, where the structure or union contains a member with array type (including, recursively, members of all contained structures and unions) refers to an object with automatic storage duration and temporary lifetime. Its lifetime begins when the expression is evaluated and its initial value is the value of

Converting this code line to C

偶尔善良 提交于 2019-12-12 06:54:10
问题 I have the following code line: for ( int i = index; i < al->size; ++i ) //i,index and size are integers.al is an arraylist When I compile this in C, I get the error: 'for' loop initial declarations are only allowed in C99 mode Im not sure on how to fix this. Thank you! 回答1: Either declare the iterator outside of the loop: int i; for (i = index; i < al->size; ++i) { do_foo(); } or if your compiler supports it, compile against the c99 or compatible standard: gcc -std=c99 your_code.c (Note that

Storing numbers as (x, y) cordinates from a file at a specific point

流过昼夜 提交于 2019-12-12 04:13:34
问题 I have an Instance File from which I need to store the NUM_PT and all the respective co-ordinates in the form of a 2D array system ( personal choice so I can access them easily ). I am able to retrieve the NUM_PT but I am stuck at reading the successive cordinates into my array. HERE IS WHAT I HAVE DONE /* Assignment 2 */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include <ctype.h> #define MAXS 256 int main(int argc, char *argv[]) { int num_pt; int inputfile

How to does a variable argument Functioncall as macro define?

余生颓废 提交于 2019-12-12 02:39:02
问题 Imagine, I have a debug source file, which is like this: #if _OWN_DEBUG_LEVEL != 0 void DebugLogMsg (DebugStruct_t *DebugStruct, size_t sizeID, char const *szFormat, ...); #else #define DebugLogMsg(_Expression1, _Expression2, _Expression3) ((void)0) #endif In this case I do not really care about the additional arguments to the function, but what about this case? #if _OWN_DEBUG_LEVEL > 0 #undef DebugLogMsg1 #define DebugLogMsg1(_Expression1, _Expression2, _Expression3) \ DebugLogMsg(

Can I use arrays as a function parameter in C99?

旧城冷巷雨未停 提交于 2019-12-12 01:14:39
问题 The C99 standard says the following in 6.7.5.3/7: A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. Which I understand as: void foo(int * arr) {} // valid void foo(int arr[]) {} // invalid However, gcc 4.7.3 will happily accept both function definitions, even when compiled with gcc -Wall -Werror -std=c99 -pedantic-errors . Since I am not a