c89

using ansi-c on windows platform can i get time of system upto milliseconds accuracy?

夙愿已清 提交于 2019-12-04 19:06:14
i need to get the millisecond accuracy i take a look on this question but i am working on windows: it gives linking errors for POSIX functions. it will be very good if i can get UTC time since 1970 with milliseconds precision. Not in ANSI C, but the Windows API provides a GetSystemTime function as illustrated here: http://msdn.microsoft.com/en-us/library/ms724950(v=VS.85).aspx Sorry, but you can't do that using neither ANSI C nor the Windows API. You can get the system time with a millisecond resolution using GetSystemTime or with a 100-nanosecond resolution using GetSystemTimeAsFileTime, but

What C99 features are considered harmful or unsupported [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-04 16:57:20
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I usually write C code in C89, now some features of C99 (like intxx_t or __VA_ARGS__ or snprintf ) are very useful, and can be even vital. Before I more my requirements from C89 to C99 I wanted to know which of C99 features were widely supported and which ones were not widely

Is negating INT_MIN undefined behaviour?

☆樱花仙子☆ 提交于 2019-12-04 12:33:05
Let's say I have a variable i that comes from external sources: int i = get_i(); Assuming i is INT_MIN and two's complement representation, is -i undefined? It depends on the platform. C supports three representations for negative numbers (see section 6.2.6.2 of the C99 standard): Two's complement. One's complement. Sign and magnitude. With one's complement and sign and magnitude, -INT_MIN is defined (and equal to INT_MAX ). With two's complement, it depends on whether the value with sign bit 1 and all value bits zero is a trap representation or a normal value. If it's a normal value, -INT_MIN

Is Visual Studio's C4028 warning (formal parameter different from declaration) spurious?

六月ゝ 毕业季﹏ 提交于 2019-12-04 12:17:53
Consider the following function declaration and definition. In the header file: void some_function(int param); In the source file: #include "test.h" void some_function(const int param) {} int main(void) { return 0; } Under Visual Studio 2010, compiling as a pure C project, I see warning C4028: formal parameter 1 different from declaration . But as far as I know, this is perfectly valid C, and fairly common practice. Am I wrong about this, and is VS2010 therefore correct to warn me? Or if it is a spurious warning, can I disable it specifically for this kind of case, but keep the warning on for

Is it legal and well defined behavior to use a union for conversion between two structs with a common initial sequence (see example)?

[亡魂溺海] 提交于 2019-12-04 10:10:15
问题 I have an API with a publicly facing struct A and an internal struct B and need to be able to convert a struct B into a struct A. Is the following code legal and well defined behavior in C99 (and VS 2010/C89) and C++03/C++11? If it is, please explain what makes it well-defined. If it's not, what is the most efficient and cross-platform means for converting between the two structs? struct A { uint32_t x; uint32_t y; uint32_t z; }; struct B { uint32_t x; uint32_t y; uint32_t z; uint64_t c; };

What is the difference between Integral Promotion and Balancing in C?

别说谁变了你拦得住时间么 提交于 2019-12-04 06:51:38
问题 What is the difference between integral promotion and balancing. Can we sum up both the rules by saying that any type is converted to atleast int or unsigned int type before performing any operation(except logical operators &&, ||, !) and to a greater type if any of the operand is of type greater than int ? 回答1: There are two different things in the standard but none is called balancing: If an int can represent all values of the original type (as restricted by the width, for a bit-field), the

c89: Convert an int to void* and back

天涯浪子 提交于 2019-12-04 04:49:48
First off, this is not a dupe of: Is it safe to cast an int to void pointer and back to int again? The difference in the questions is this: I'm only using the void* to store the int, but I never actually use it as a void*. So the question really comes down to this: Is a void * guaranteed to be at least as wide as an int I can't use intptr_t because I'm using c89 / ANSI C. EDIT In stdint.h from C99 ( gcc version ) I see the following: /* Types for `void *' pointers. */ #if __WORDSIZE == 64 # ifndef __intptr_t_defined typedef long int intptr_t; # define __intptr_t_defined # endif typedef

How to get SIZE_MAX in C89

柔情痞子 提交于 2019-12-04 03:58:42
问题 I'm trying to get SIZE_MAX in C89. I thought of the following way to find SIZE_MAX : const size_t SIZE_MAX = -1; Since the standard (§6.2.1.2 ANSI C) says: When a signed integer is converted to an unsigned integer with equal or greater size, if the value of the signed integer is nonnegative, its value is unchanged. Otherwise: if the unsigned integer has greater size, the signed integer is first promoted to the signed integer corresponding to the unsigned integer; the value is converted to

Returning the terminal cursor to start-of-line with wrapping enabled

对着背影说爱祢 提交于 2019-12-04 01:01:36
问题 I'm writing a filter (in a pipe destined for a terminal output) that sometimes needs to "overwrite" a line that has just occurred. It works by passing stdin to stdout character-by-character until a \n is reached, and then invoking special behaviour. My problem regards how to return to the beginning of the line. The first thing I thought of was using a \r or the ANSI sequence \033[1G . However, if the line was long enough to have wrapped on the terminal (and hence caused it to scroll), these

Should I use “-ansi” or explicit “-std=…” as compiler flags?

≡放荡痞女 提交于 2019-12-04 00:59:00
I've read that ANSI C is not exactly the same as ISO C and compilers may differ in interpretation of what "-ansi" is about. (gcc maps it to C90, clang maps it to C89) At the moment I would tend to use "-std=..." over "-ansi" as then it is explicitly shown which standard is used. As I am specifically interested in compiling on Linux, Windows and MAC, I fear some compilers could not understand "-std=..." but "-ansi". So are there any pros and cons for using the one over the other? If you want the compiler to enforce the 1989 ANSI C standard, or equivalently the 1990 ISO C standard (they describe