c99

How to set environment variable in ISO c99 Standard C without setenv()?

旧城冷巷雨未停 提交于 2020-01-25 12:00:13
问题 I can't use setenv() from stdlib.h for C99 standard compiler as it is not available. Is there any other function to set an environment variable in C99? 回答1: getenv is thus part of the C90 standard which is included in C99 but setenv is only conform to an IEEE standard so it hasn't to be included in strictly standard C99. Moreover, the corresponding IEEE is from 2001. This means there isn't any standard way of doing this in C99, you have to use platform-specific code to set the env. On the

BackTracking function is not working as expected

微笑、不失礼 提交于 2020-01-25 10:13:31
问题 I am trying to solve the following question using BackTracking in C but I don't know how to continue from here... The question is: Chris is planning to travel in a country with N cities. He will get help from a matrix NxN that the cell (I,J) represents the length of the road from city I to City J. The length of the road from City A to city B is not the same when compared to the road from City B to City A. The Road From the same source city back to it (directly) is 0. Chris noticed that the

C preprocessor macro doesn't parse comma separated tokens?

白昼怎懂夜的黑 提交于 2020-01-24 20:21:29
问题 I want to choose one of two functions depending on the number of arguments: nargs = 0 ----> f1 nargs > 0 ----> f2. Macros do the following: get the first argument, then if no argument supplied ,it would add two commas " ,NULL,NULL ". Then it would select the second argument from the returned list of arguments. for example: f("Hello, world%i%s", x , s) ----> " Hello, world%i%s " ----> void f() ----> ,NULL,NULL ----> NULL so I can get null or void depending the on number of arguments. Here is

C preprocessor macro doesn't parse comma separated tokens?

六月ゝ 毕业季﹏ 提交于 2020-01-24 20:20:07
问题 I want to choose one of two functions depending on the number of arguments: nargs = 0 ----> f1 nargs > 0 ----> f2. Macros do the following: get the first argument, then if no argument supplied ,it would add two commas " ,NULL,NULL ". Then it would select the second argument from the returned list of arguments. for example: f("Hello, world%i%s", x , s) ----> " Hello, world%i%s " ----> void f() ----> ,NULL,NULL ----> NULL so I can get null or void depending the on number of arguments. Here is

Are literal suffixes needed in standard C?

ⅰ亾dé卋堺 提交于 2020-01-24 00:17:18
问题 There is a question already answering the particular case of variable declaration, but what about other literal constant uses? For example: uint64_t a; ... int32_t b = a / 1000000000; Is last piece of code equivalent to next one in any standard C compiler? uint64_t a; ... int32_t b = (int32_t)(a / UINT64_C(1000000000)); In other words, are xINTn_C macros needed at all (supposing we are using explicit casting in cases where implicit one is wrong)? EDIT When compiler reads 1000000000 , is it

What Can I Use Besides usleep in a Modern POSIX Environment?

自作多情 提交于 2020-01-21 12:03:36
问题 I'm fairly new to C but writing a small multithreaded application. I want to introduce a delay to a thread. I'd been using 'usleep' and the behavior is what I desire - but it generates warnings in C99. implicit declaration of function ‘usleep’ It's only a warning, but it bothers me. I've Googled for an answer but all I could find was a while-loop / timer approach that seemed like it would be CPU intensive. EDIT: My includes are: #include <stdio.h> #include <stdlib.h> #include <pthread.h>

Is there a difference between initializing a variable and assigning it a value immediately after declaration?

流过昼夜 提交于 2020-01-20 07:08:18
问题 Assuming a purely non-optimizing compiler, is there any difference in machine code between initializing a variable and assigning it a value after declaration? Initialization method : int x = 2; Assignment method : int x; x = 2; I used GCC to output the assembly generated for these two different methods and both resulted in a single machine instruction: movl $2, 12(%esp) This instruction just sets the memory held by the x variable to the value of 2 . GCC may be optimizing this because it can

Is there a difference between initializing a variable and assigning it a value immediately after declaration?

空扰寡人 提交于 2020-01-20 07:07:29
问题 Assuming a purely non-optimizing compiler, is there any difference in machine code between initializing a variable and assigning it a value after declaration? Initialization method : int x = 2; Assignment method : int x; x = 2; I used GCC to output the assembly generated for these two different methods and both resulted in a single machine instruction: movl $2, 12(%esp) This instruction just sets the memory held by the x variable to the value of 2 . GCC may be optimizing this because it can

int_max in 32 bit vs 64 bit environment

Deadly 提交于 2020-01-16 04:26:06
问题 Is INT_MAX different between a 32-bit and 64-bit environment? It seems like it would be the case, though I've heard people say that the 64-bit environment just uses the 32-bit environment's INT_MAX. 回答1: It depends on the system. On Intel Linux they are the same. check limits.h 回答2: Your question is perhaps too generic, but on typical 64bit enviroment (x86-64) int is defacto the same size as on 386 (keeping in mind that this also depends on OS, not just architecture). C standard only limits

Difference between UINT32_C and uint32_t

北城余情 提交于 2020-01-14 08:04:17
问题 As far as I know the suffix t in uint32_t denote t ype name but I wonder to know what is the C in UINT32_C and what is the differences? 回答1: UINT32_C is a macro which defines integer constant of type uint_least32_t . For example: UINT32_C(123) // Might expand to 123UL on system where uint_least32_t is unsigned long // or just 123U, if uint_least32_t is unsigned int. 7.20.4.1 Macros for minimum-width integer constants The macro INT N _C( value ) shall expand to an integer constant expression