c

How to use C defines in ARM assembler

How can I use external defines such as LONG_MIN and LONG_MAX in ARM assembler code? Let's say my_arm.h looks like this: int my_arm(int foo); Let's say I have a my_main.c as follows: ... #include <limits.h> #include "my_arm.h" ... int main (int argc, char *argv[]) { int foo=0; ... printf("My arm assembler function returns (%d)...

Why no memory leak?

The following is designed to take a variable length constant char and print it out in a nice format for logging. I am certain readers will have suggestions on how this can be improved, and I'd welcome it. What puzzles me is that I expected it would be necessary to free() the returned static char each time ToHexString() is called. Inst...

iPhone SDK: Please explain why "nil ==" is different than "== nil"

I have been programming iPhone SDK for around 6 months but am a bit confused about a couple of things...one of which I am asking here: Why are the following considered different? if (varOrObject == nil) { } vs if (nil == varOrObject) { } Coming from a perl background this is confusing to me... Can someone please explain why on...

Good tutorial to create Win32 toolbar?

I want to add a toolbar and know which tool was clicked. I'd also like to be able to change the toolbar's buttons' bitmap after theyve been created MSDN is fairly breif on all of this. Thanks ...

Expected segmentation fault, as soon as assigning a value to index 1?

Hello, In the code snippet, I expected a segmentation fault as soon as trying to assign a value to count[1]. However the code continues and executes the second for-loop, only indicating a segmentation fault when the program terminates. #include <stdio.h> int main() { int count[1]; int i; for(i = 0; i < 100; i...

One thread reading and another writing to volatile variable - thread-safe?

In C I have a pointer that is declared volatile and initialized null. void* volatile pvoid; Thread 1 is occasionally reading the pointer value to check if it is non-null. Thread 1 will not set the value of the pointer. Thread 2 will set the value of a pointer just once. I believe I can get away without using a mutex or condition ...

How to exclude a function from a call graph in Doxygen?

I have debugging functions that are called in just about every function of a large program. They are conditionally turned on by a defined macro variable. I don't want these showing up in call graphs, since I can be fairly sure that every function has them. Is there a way to exclude the function from the graph /*! Step 3: * @callgrap...

Which socket, the clientSocket = accept() or the listen(socket), do you setsockopt SO_KEEPALIVE on?

Which socket, the clientSocket = accept() or the listen(socket), do you setsockopt SO_KEEPALIVE on to get the connection to clients not to drop? ...

Bits and byte operation.

/* Bit Masking */ /* Bit masking can be used to switch a character between lowercase and uppercase */ #define BIT_POS(N) ( 1U << (N) ) #define SET_FLAG(N, F) ( (N) |= (F) ) #define CLR_FLAG(N, F) ( (N) &= -(F) ) #define TST_FLAG(N, F) ( (N) & (F) ) #define BIT_RANGE(N, M) ( BIT_POS((M)+1 - (N))-1 << (N) ) #define BIT_SHIFTL(B, N) ( (unsi...

How to check any thread is working currently

I know there is one for multi processes waitpid(-1,WNOHANG,NULL) that is non-blocking function call to check if there is any child process currently working on But is there any similar lib function to check for multithread? All i want to do is check if there is any thread currently on, if not reset some global values. ...

Is there a function to set a process stack/heap memory allocation?

I know this is an OS function. But is there a way of increasing your overall stack or heap size through C? sbrk() is used to change the size of data segment right? Does this imply both stack and heap? ...

What would a garbage collector do here?

I saw this bit of code in another thread void foo { int *n = malloc(sizeof(int)); *n = 10; n++; printf("%d", *n); } The mistake here is obvious. n isn't being dereferenced. There is a memory leak. Let's assume there is a garbage collector working here. The reference count to our initial value of n is zero now because n isn't...

Input/output stream abstraction layers for plain C

Are there any widely used I/O stream abstraction layers for plain C? By an I/O stream abstraction layer I mean any layer that at least allows the creation of custom read/write functions. For C++, there's the standard iostream and boost::iostreams. For glibc users, there's a possibility to use custom streams. These won't do any good if t...

TEvent.WaitFor in Kylix

In Kylix TEvent.WaitFor(Timeout) method only accepts Timeout of $FFFFFFFF, otherwise it generates an error. Internally it uses sem_wait function which doesn't have a timeout parameter. It there any way around this? I need to set a timeout parameter. ...

Have you ever crashed a debugger?

The title says it all. Recently I was debugging a project and the debugger (GDB 7.1) crashed all of a sudden, because of an endless recursion while trying to print a graph structure. At first I couldn't even imagine that a debugger could crash (a stable version) but it had. So it's really interesting to me, have you ever crashed a debugg...

sprintf not copying?

I am writing a fuzzer that using the system() function and I need to copy: char a[1100]; /* full of A's with null ending */ into: char tmp[10000]; I used: sprintf(tmp, "%s", a); When I printf tmp there is nothing printed. What am I doing wrong? ...

Given a pointer to member a within a struct, write a routine that returns a pointer to the struct.

Here is an interview question that I saw on some forum. I've been trying to figure out how it works but I don't quite get it. Could somebody explain how it works? Q: Given a pointer to member a within a struct, write a routine that returns a pointer to the struct. struct s { ... int a; … }; struct s *get_s_ptr(int *a_ptr) ...

What can glStencil do?

I'm wondering what the stencil buffer is and what it can do. Thanks ...

Any libraries of reading & writing binary file formats (PE & ELF)?

HellO, I want to write a binary file format viewer for windows which can operate on both PE & ELF files. Similar to the ones already there: PE Explorer http://www.pe-explorer.com/ PE VIew: http://www.magma.ca/~wjr/ PEBrowse Professional http://www.smidgeonsoft.prohosting.com/pebrowse-pro-file-viewer.html I've reasons why I want to ...

Adding printf to the starting of all functions in a file

I have some very large C files, having lots of functions. I need to trace the execution path at run time. There is no way I can trace it through debugging as its a hypervisor code currently running over qemu and doing a lot of binary translations. Can anyone point me to some script in Perl or Python which can add a printf at the startin...