c89

How to rewrite C-struct designated initializers to C89 (resp MSVC C compiler)

故事扮演 提交于 2019-11-30 17:42:32
guys, I've this problem: Normally in C99 GCC (cygwin / MinGW / linux), there is dot-notation syntax for initializers in C struct. Like this: //HELP ME HOW TO REWRITE THIS (in most compact way) to MSVC static struct my_member_t my_global_three[] = { {.type = NULL, .name = "one"}, {.type = NULL, .name = "two"}, {.type = NULL, .name = "three"}, }; Having my_memeber_t defined in header file as: struct my_member_t { struct complex_type * type; char * name; int default_number; void * opaque; }; I'm compiling linux code in MSVC 9.0 (Visual Studio 2008), on cygwin/MinGW this works ok. BUT cl is unable

Clearing screen and kbhit() function

耗尽温柔 提交于 2019-11-30 10:03:17
问题 I got some problems writing my snake game program. I need to make game working on linux and windows. I found some topics how to clear screen on linux and windows using the #ifdef Windows etc. The problem is i need to use C89 standard, and im not sure that system("cls") is in C89. Could you help me with finding C89 functions to clear screen, and tell me something about kbhit() function on linux? Sorry for my english, and thanks for help. 回答1: C89 does not have terminal handling functions.

C89 vs c99 GCC compiler

孤街浪徒 提交于 2019-11-30 09:05:53
Is there a difference if I compile the following program using c89 vs c99? I get the same output. Is there really a difference between the two? #include <stdio.h> int main () { // Print string to screen. printf ("Hello World\n"); } gcc -o helloworld -std=c99 helloworld.c vs gcc -o helloworld -std=c89 helloworld.c Alok Singhal // comments are not a part of C89 but are OK in C99, falling off of main() without returning any value is equivalent to return 0; in C99, but not so in C89. From N1256 (pdf), 5.1.2.2.3p1: If the return type of the main function is a type compatible with int , a return

Inconsistent behaviour of implicit conversion between unsigned and bigger signed types

夙愿已清 提交于 2019-11-30 08:38:35
Consider following example: #include <stdio.h> int main(void) { unsigned char a = 15; /* one byte */ unsigned short b = 15; /* two bytes */ unsigned int c = 15; /* four bytes */ long x = -a; /* eight bytes */ printf("%ld\n", x); x = -b; printf("%ld\n", x); x = -c; printf("%ld\n", x); return 0; } To compile I am using GCC 4.4.7 (and it gave me no warnings): gcc -g -std=c99 -pedantic-errors -Wall -W check.c My result is: -15 -15 4294967281 The question is why both unsigned char and unsigned short values are "propagated" correctly to (signed) long , while unsigned int is not ? Is there any

K&R Exercise 1.16 - Limitation on line length

假如想象 提交于 2019-11-30 08:34:13
I'm learning C from K&R's " The C Programming Language " book. I'm doing the exercises specified in the book. I'm on exercise number 1.16, but I don't understand it. Exercise 1.16: Revise the main routine of the longest-line program so it will correctly print the length of arbitrarily long input lines, and as much as possible of the text. My questions: "...as much as possible of the text..." - is there some limitation on string length? Maybe in standard headers there's a variable with the max allowed value of string length? "...the length of arbitrarily long input lines..." - but in the code

C90: How do I globally initialize this struct in C without C99 extensions

江枫思渺然 提交于 2019-11-30 07:41:18
I was wondering what the best way to initialize this struct is with C90, while still keeping it neat. In my header file, call it test.h, I have the following struct defined: struct s_test_cfg{ char *a[3]; char *b[3]; char *c[3]; } Then I have it declared as an extern struct so that I can initialize it globally in the .c file: extern struct s_test_cfg test_cfg; Now in my .c file, I want to be able to declare something like this globally (obviously what I'm about to write is unsupported in C90): struct s_test_cfg test_cfg = { .a = {"a", "b", "c"},\ .b = {"d", "e", "f"},\ .c = {"g", "h", "i"} };

Order of expression evaluation in C

久未见 提交于 2019-11-30 05:35:43
问题 If I have the following expression: c = (a) * (b) What does the C90 standard say about the order evaluation of the subexpression 'a' and 'b'? 回答1: There is no specified order since the multiplication operator is not a sequence point. Sequence points include the comma operator, the end of a full expression, and function calls. Thus the order of evaluation of (a) and (b) is up to the compiler implementation. Therefore you shouldn't attempt to-do something in (a) that would have a side-effect

How to rewrite C-struct designated initializers to C89 (resp MSVC C compiler)

白昼怎懂夜的黑 提交于 2019-11-30 01:08:26
问题 guys, I've this problem: Normally in C99 GCC (cygwin / MinGW / linux), there is dot-notation syntax for initializers in C struct. Like this: //HELP ME HOW TO REWRITE THIS (in most compact way) to MSVC static struct my_member_t my_global_three[] = { {.type = NULL, .name = "one"}, {.type = NULL, .name = "two"}, {.type = NULL, .name = "three"}, }; Having my_memeber_t defined in header file as: struct my_member_t { struct complex_type * type; char * name; int default_number; void * opaque; }; I'm

What techniques/strategies do people use for building objects in C (not C++)?

纵然是瞬间 提交于 2019-11-30 00:57:36
I am especially interested in objects meant to be used from within C, as opposed to implementations of objects that form the core of interpreted languages such as python. I tend to do something like this: struct foo_ops { void (*blah)(struct foo *, ...); void (*plugh)(struct foo *, ...); }; struct foo { struct foo_ops *ops; /* data fields for foo go here */ }; With these structure definitions, the code implementing foo looks something like this: static void plugh(struct foo *, ...) { ... } static void blah(struct foo *, ...) { ... } static struct foo_ops foo_ops = { blah, plugh }; struct foo

How to read UTF-8 string given its length in characters in plain C89?

血红的双手。 提交于 2019-11-29 21:25:49
问题 I'm writing a custom cross-platform minimalistic TCP server in plain C89. (But I will also accept POSIX-specific answer.) The server works with UTF-8 strings, but never looks inside them. It treats all strings as immutable binary blobs. But now I need to accept UTF-8 strings from the client that does not know how to calculate their size in bytes. The client can only transmit string length in characters. (Update: The client is in JavaScript, and "length in characters" is, in fact, whatever