ansi-c

Why doesn't ANSI C have namespaces?

久未见 提交于 2019-11-26 07:54:46
问题 Having namespaces seems like no-brainer for most languages. But as far as I can tell, ANSI C doesn\'t support it. Why not? Any plans to include it in a future standard? 回答1: C does have namespaces. One for structure tags, and one for other types. Consider the following definition: struct foo { int a; }; typedef struct bar { int a; } foo; The first one has tag foo, and the later is made into type foo with a typedef. Still no name-clashing happens. This is because structure tags and types

What is the difference between C, C99, ANSI C and GNU C?

余生颓废 提交于 2019-11-26 06:04:04
问题 I have started programming practice on codechef and have been confused by the difference between C and C99. What does C mean here? Is it C89? Check the languages at the bottom of this submit. It contains both C and C99. I found on the internet something called GNU C. Is there a different C for linux/unix systems? Are these compliant to the C standards by ANSI? I have also read in some places \"C99 strict\". What is this? Are there any other different standards of C in use? Is there something

How to convert an enum type variable to a string?

落花浮王杯 提交于 2019-11-26 01:44:31
问题 How to make printf to show the values of variables which are of an enum type? For instance: typedef enum {Linux, Apple, Windows} OS_type; OS_type myOS = Linux; and what I need is something like printenum(OS_type, \"My OS is %s\", myOS); which must show a string \"Linux\", not an integer. I suppose, first I have to create a value-indexed array of strings. But I don\'t know if that is the most beautiful way to do it. Is it possible at all? 回答1: There really is no beautiful way of doing this.

How to convert an enum type variable to a string?

会有一股神秘感。 提交于 2019-11-25 18:51:30
How to make printf to show the values of variables which are of an enum type? For instance: typedef enum {Linux, Apple, Windows} OS_type; OS_type myOS = Linux; and what I need is something like printenum(OS_type, "My OS is %s", myOS); which must show a string "Linux", not an integer. I suppose, first I have to create a value-indexed array of strings. But I don't know if that is the most beautiful way to do it. Is it possible at all? Bo Persson There really is no beautiful way of doing this. Just set up an array of strings indexed by the enum. If you do a lot of output, you can define an