What is time_t ultimately a typedef to?
I searched my Linux box and saw this typedef: typedef __time_t time_t; But I could not find the __time_t definition. 11 Answers 11
I searched my Linux box and saw this typedef: typedef __time_t time_t; But I could not find the __time_t definition. 11 Answers 11
In a reputable source about C, the following information is given after discussing the & operator: … It’s a bit unfortunate that the terminology [address of] remains, because it confuses those who don’t know what addresses are about, and misleads those who do: thinking about pointers as if they were addresses usually leads to grief… … Read more
I get an error on line 6 (initialize my_foo to foo_init) of the following program and I’m not sure I understand why. typedef struct foo_t { int a, b, c; } foo_t; const foo_t foo_init = { 1, 2, 3 }; foo_t my_foo = foo_init; int main() { return 0; } Keep in mind this … Read more
I want to write a macro in C that accepts any number of parameters, not a specific number example: #define macro( X ) something_complicated( whatever( X ) ) where X is any number of parameters I need this because whatever is overloaded and can be called with 2 or 4 parameters. I tried defining the … Read more
In the following bit of code, pointer values and pointer addresses differ as expected. But array values and addresses don’t! How can this be? Output my_array = 0022FF00 &my_array = 0022FF00 pointer_to_array = 0022FF00 &pointer_to_array = 0022FEFC #include <stdio.h> int main() { char my_array[100] = “some cool string”; printf(“my_array = %p\n”, my_array); printf(“&my_array = %p\n”, … Read more
In C, is it possible to forward the invocation of a variadic function? As in, int my_printf(char *fmt, …) { fprintf(stderr, “Calling printf with fmt %s”, fmt); return SOMEHOW_INVOKE_LIBC_PRINTF; } Forwarding the invocation in the manner above obviously isn’t strictly necessary in this case (since you could log invocations in other ways, or use vfprintf), … Read more
In one of my project source files, I found this C function definition: int (foo) (int *bar) { return foo (bar); } Note: there is no asterisk next to foo, so it’s not a function pointer. Or is it? What is going on here with the recursive call? 3 Answers 3
I recently had a test in my class. One of the problems was the following: Given a number n, write a function in C/C++ that returns the sum of the digits of the number squared. (The following is important). The range of n is [ -(10^7), 10^7 ]. Example: If n = 123, your function … Read more
I have two macros FOO2 and FOO3: #define FOO2(x,y) … #define FOO3(x,y,z) … I want to define a new macro FOO as follows: #define FOO(x,y) FOO2(x,y) #define FOO(x,y,z) FOO3(x,y,z) But this doesn’t work because macros do not overload on number of arguments. Without modifying FOO2 and FOO3, is there some way to define a macro … Read more
According to Linux programmers manual: brk() and sbrk() change the location of the program break, which defines the end of the process’s data segment. What does the data segment mean over here? Is it just the data segment or data, BSS, and heap combined? According to wiki Data segment: Sometimes the data, BSS, and heap … Read more