c

Do threads share the heap?

As far as I know each thread gets a distinct stack when the thread is created by the OS. I wonder if each thread has a heap distinct to itself also? ...

Volatile variable

Where is a volatile variable stored in the stored in program memory(in which section) ? ...

Is %d a cast in C?

int a; printf("%d\n", a); I wonder if %d is a cast? ...

What is the size of void?

What would this statement yield? void * p = (void*) malloc(sizeof(void)); Edit: An extension to the question. If sizeof(void) yields 1 in GCC compiler, then 1 byte of memory is allocated and the pointer p points to that byte and would p++ be incremented to 0x2346? Suppose p was 0x2345. I am talking about p and not *p. ...

Is typedef and #define the same in c?

I wonder if typedef and #define the same in c? ...

How to run a C program in DOS prompt

I want to run a C program in DOS prompt. Is it possible? ...

How to use extended precision cmath functions by preference

My question is this: is there a way to always use the extended precision versions of mathematical functions - such as sqrt, exp, &c - without using an explicit cast when providing a single or double precision argument? For example I want this functionality, without the hassle of the casting: float x=15.0; float answer; answer=sqrt((l...

Is it possible to generate a DLL using Turbo C/C++ compiler ??

I need this for calling a C function from Java class (JNI) and I know that there are options to do this using "Microsoft Visual C++ compiler". (explained here) But I am interested to know if something similar can be done using TC or TCC. I don't have a copy of "Microsoft Visual C++" and not sure if cl.exe is available without having to...

Question about pointers in Objective-C

In a global.h file I declare dataManager *IdataManager; Then later when the program initializes I allocate and initialize the variable, and use it in several different views as a means of accessing a set of data that gets downloaded when the app starts up. Recently I noticed when I pull up one of my views, close it, and then open it ...

Change string pointed by pointer

hi friends Many functions in c take pointer to constant strings/chars as parameters eg void foo(const char *ptr) . However I wish to change the string pointed by it (ptr).how to do it in c ...

gethostbyname problem

I wish to use "gethostbyname" in my Suse m/c but it is not returning any structure. but on the other systems it is working fine what could be the issue with my m/c ?? ...

Problem with mmap/munmap - getting a bus error after the 783rd iteration?!?

Okay, here's the setup: I work in HPC, and we're preparing for the need to scale up to tens of thousands of nodes. To deal with this, I've implemented a local process that caches information on each node to reduce the amount of network traffic. It then exposes this information via shared-memory. The basic logic is that there is one well-...

How portable is casting -1 to an unsigned type?

The other day, I came across this construct: static_cast<size_type>(-1) in some example C++ code, which is likely (depending on the details of where size_type is from) to be equivalent to the following C: (size_t)(-1) As I understand it, it works based on the fact that the representation of -1 in twos complement arithmetic is 11111...

Can likely/unlikely macros be used in user-space code?

I came across these 2 macros in Linux kernel code. I know they are instructions to compiler (gcc) for optimizations in case of branching. My question is, can we use these macros in user space code? Will it give any optimization? Any example will be very helpful. ...

How much memory does a constant take in C?

when doing like this: const int a = 5; I wonder if a will get 4-byte of memory just like a variable ? (in 32 bit system) ...

C code for loading bitmap

Hi everyone, Does anybody know a good C sample that loads bitmaps and handles all the cases: rle, b/w bitmaps, so on? Code should be cross-platform. Thanks. ...

Unknown meta-character in C/C++ string literal ?

I created a new project with the following code segment: char* strange = "(Strange??)"; cout << strange << endl; resulting in the following output: (Strange] Thus translating '??)' -> ']' Debugging it shows that my char* string literal is actually that value and it's not a stream translation. This is obviously not a meta-charac...

strcat problem in C, segmentation fault

Hello everyone! i am new to C and recently i have a problem with a strcat function. I have an array of arguments defined like: #define MAXARGS 10; char *argvalues[MAXARGS]; All i want is to concatenate the last non-null element of the array with a null terminator. Here is the piece of my code for that: while (argvalues[i] != NULL) ...

How to get a file length in c?

I just have a quick question about how to get the length of a file containing hexadecimal numbers. For example: 724627916C The only way I can think is to convert hex value to binary: 724627916C => 0111001001000110001001111001000101101100 then count the bits of binary value. Just wondering if this is the correct way? Thanks ...

Scanf skips every other while loop in C

I'm trying to develop a simple text-based hangman game, and the main game loop starts with a prompt to enter a guess at each letter, then goes on to check if the letter is in the word and takes a life off if it isn't. However, when I run the game the prompt comes up twice each time, and the program doesn't wait for the user's input. It a...