c99

Why is the fgets function deprecated?

夙愿已清 提交于 2019-11-26 11:03:57
问题 From The GNU C Programming Tutorial: The fgets (\"file get string\") function is similar to the gets function. This function is deprecated -- that means it is obsolete and it is strongly suggested you do not use it -- because it is dangerous. It is dangerous because if the input data contains a null character, you can\'t tell. Don\'t use fgets unless you know the data cannot contain a null. Don\'t use it to read files edited by the user because, if the user inserts a null character, you

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

Create statically-linked binary that uses getaddrinfo?

佐手、 提交于 2019-11-26 10:35:38
问题 I have included the header netdb.h , where getaddrinfo is included, but gcc issues this warning: warning: Using \'getaddrinfo\' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking gcc -m32 -static -s -O2 -std=c99 -D_POSIX_C_SOURCE=200112L myprogram.c How can I statically compile whatever file is missing ? Possible solutions: It could be that the glibc installation is missing the corresponding object file necessary for static

Is there any reason not to use fixed width integer types (e.g. uint8_t)?

做~自己de王妃 提交于 2019-11-26 10:35:03
问题 Assuming you\'re using a compiler that supports C99 (or even just stdint.h), is there any reason not to use fixed width integer types such as uint8_t? One reason that I\'m aware of is that it makes much more sense to use char s when dealing with characters instead of using (u)int8_t s, as mentioned in this question. But if you are planning on storing a number, when would you want to use a type that you don\'t know how big it is? I.e. In what situation would you want to store a number in a

What is the use of the `inline` keyword in C?

最后都变了- 提交于 2019-11-26 10:31:27
问题 I read several questions in stackoverflow about inline in C but still am not clear about it. static inline void f(void) {} has no practical difference with static void f(void) {} . inline void f(void) {} in C doesn\'t work as the C++ way. How does it work in C? What actually does extern inline void f(void); do? I never really found a use of the inline keyword in my C programs, and when I see this keyword in other people\'s code, it\'s almost always static inline , in which I see no difference

Literal string initializer for a character array

孤人 提交于 2019-11-26 10:17:44
问题 In the following rules for the case when array decays to pointer: An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T. (The exceptions are when the array is the operand of a sizeof or & operator, or is a literal string initializer for a character array.) How to understand the case when the array is \"literal string initializer for a character array\"

Does C99 guarantee that arrays are contiguous?

帅比萌擦擦* 提交于 2019-11-26 09:42:55
问题 Following an hot comment thread in another question, I came to debate of what is and what is not defined in C99 standard about C arrays. Basically when I define a 2D array like int a[5][5] , does the standard C99 garantee or not that it will be a contiguous block of ints, can I cast it to (int *)a and be sure I will have a valid 1D array of 25 ints. As I understand the standard the above property is implicit in the sizeof definition and in pointer arithmetic, but others seems to disagree and

How to wrap printf() into a function or macro?

放肆的年华 提交于 2019-11-26 09:26:09
问题 This sounds a little like an interview question,but is actually a practical problem. I am working with an embedded platform, and have available only the equivalents of those functions: printf() snprintf() Furthermore, the printf() implementation (and signature) is likely to change in the near future, so calls to it have to reside in a separate module, in order to be easy to migrate later. Given those, can I wrap logging calls in some function or macro? The goal is that my source code calls

What is the official status of C99 support in VS2013?

孤街浪徒 提交于 2019-11-26 09:02:40
问题 I see that VS2013 added support for a large number of major core language features of C99. Now it supports compound literals, designated initializers, variadic macros, interleaved declarations and statements just to name a few. This indicates that VS developers made serious steps towards C99 support in Visual Studio. Yet, some of these features are not part of C++ language, which appears to be a notable deviation from the previously announced development strategy (e.g. \"VS C compiler will

Which C99 features are available in the MS Visual Studio compiler?

梦想与她 提交于 2019-11-26 08:26:55
问题 It\'s well known that Microsoft\'s Visual Studio compiler does not support C99, and it looks like they have no plans to support it. However, the compiler does include some cherry picked features such as variadic macros and long long - see the quotes in this answer: Where we’ve received many requests for certain C99 features, we’ve tried to implement them (or analogues). A couple examples are variadic macros, long long , __pragma , __FUNCTION__ , and __restrict . If there are other C99