c99

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

大城市里の小女人 提交于 2019-11-27 20:23:24
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 at first most people would say, "but that range implies at least 16-bits!" But C doesn't require two's

Is the behavior of subtracting two NULL pointers defined?

两盒软妹~` 提交于 2019-11-27 20:20:39
Is the difference of two non-void pointer variables defined (per C99 and/or C++98) if they are both NULL valued? For instance, say I have a buffer structure that looks like this: struct buf { char *buf; char *pwrite; char *pread; } ex; Say, ex.buf points to an array or some malloc'ed memory. If my code always ensures that pwrite and pread point within that array or one past it, then I am fairly confident that ex.pwrite - ex.pread will always be defined. However, what if pwrite and pread are both NULL. Can I just expect subtracting the two is defined as (ptrdiff_t)0 or does strictly compliant

How to declare an inline function in C99 multi-file project?

谁都会走 提交于 2019-11-27 19:43:56
I want to define an inline function in a project, compiled with c99. How can I do it? When I declare the function in a header file and give the detail in a .c file, the definition isn't recognized by other files. When I put the explicit function in a header file, I have a problem because all .o files who use it have a copy of the definition, so the linker gives me a "multiple definition" error. What I am trying to do is something like: header.h inline void func() { do things... } lib1.c #include "header.h" ... lib2.c #include "header.h" with a utility which uses both lib1.o and lib2.o

32 bit Windows and the 2GB file size limit (C with fseek and ftell)

为君一笑 提交于 2019-11-27 18:44:50
问题 I am attempting to port a small data analysis program from a 64 bit UNIX to a 32 bit Windows XP system (don't ask :)). But now I am having problems with the 2GB file size limit (long not being 64 bit on this platform). I have searched this website and others for possible sollutions but cannot find any that are directly translatable to my problem. The problem is in the use of fseek and ftell. Does anyone know of a modification to the following two functions to make them work on 32 bit Windows

Is there any option to switch between C99 and C11 C standards in Visual Studio?

帅比萌擦擦* 提交于 2019-11-27 17:43:34
问题 I am new to Visual Studio Environment and I am using VS2017 Pro. I wanted to write simple program in C and compiled with both c99 and c11 standards. In Visual Studio, I could only find compiler switches for C++ standards only. How can we tell visual studio environment that we want to compile current code with c99 and c11 C standards. 回答1: The only 'modes' supported by Visual C++ are: /std:c++14 mode for C++14 conformance (the default), /std:c++17 mode for C++17 support which is not quite

GCC: accuracy of strict aliasing warnings

為{幸葍}努か 提交于 2019-11-27 17:21:08
问题 I'm trying to check some of my code for strict aliasing violations, but it looks like I've missed something while trying to understand the strict aliasing rule. Imagine the following code: #include <stdio.h> int main( void ) { unsigned long l; l = 0; *( ( unsigned short * )&l ) = 1; printf( "%lu\n", l ); return 0; } Classic and basic example. With GCC 4.9 ( -Wall -fstrict-aliasing -Wstrict-aliasing -O3 ), it actually reports the error: dereferencing type-punned pointer will break strict

What are the incompatible differences between C(99) and C++(11)?

谁都会走 提交于 2019-11-27 17:17:23
This question was triggered by replie(s) to a post by Herb Sutter where he explained MS's decision to not support/make a C99 compiler but just go with the C(99) features that are in the C++(11) standard anyway. One commenter replied : (...) C is important and deserves at least a little bit of attention. There is a LOT of existing code out there that is valid C but is not valid C++. That code is not likely to be rewritten (...) Since I only program in MS C++, I really don't know "pure" C that well, i.e. I have no ready picture of what details of the C++-language I'm using are not in C(99) and I

What are “extended integer types”?

社会主义新天地 提交于 2019-11-27 16:13:51
问题 Quoting from the book I'm reading: signed char, signed short int, signed int, signed long int, signed long long int are called standard signed integer types unsigned char, unsinged short int, unsigned int, unsigned long int, unsinged long long int, _Bool are called standard unsigned integer types In addition to the standard integer types, the C99 standard allows implementation-defined extended integer types , both signed and unsigned. For example, a compiler might be provide signed and

Declaring an array of negative length

泄露秘密 提交于 2019-11-27 16:00:47
What happens in C when you create an array of negative length? For instance: int n = -35; int testArray[n]; for(int i = 0; i < 10; i++) testArray[i]=i+1; This code will compile (and brings up no warnings with -Wall enabled), and it seems you can assign to testArray[0] without issue. Assigning past that gives either a segfault or illegal instruction error, and reading anything from the array says "Abort trap" (I'm not familiar with that one). I realize this is somewhat academic, and would (hopefully) never come up in real life, but is there any particular way that the C standard says to treat

What does GCC __attribute__((mode(XX)) actually do?

我们两清 提交于 2019-11-27 15:42:15
问题 This arose from a question earlier today on the subject of bignum libraries and gcc specific hacks to the C language. Specifically, these two declarations were used: typedef unsigned int dword_t __attribute__((mode(DI))); On 32 bit systems and typedef unsigned int dword_t __attribute__((mode(TI))); On 64-bit systems. I assume given this is an extension to the C language that there exists no way to achieve whatever it achieves in current (C99) standards. So my questions are simple: is that