c

How do I start threads in plain C?

I have used fork() in C to start another process. How do I start a new thread? ...

What are bad programming practices in C?

I would just like a few things that you guys see as bad programing practices in pure C, so I can watch out for those. ...

How to use getaddrinfo_a to do async resolve with glibc

An often overlooked function that requires no external library, but basically has no documentation whatsoever. ...

Open source PDF library for C/C++ application?

I want to be able to generate PDF ouput from my (native) C++ Windows application. Are there any free/open source libraries available to do this? I looked at the answers to this question, but they mostly relate to .Net. ...

Confused by gdb print ptr vs print "%s"

1167 ptr = (void*)getcwd(cwd, MAX_PATH_LENGTH-1); (gdb) n 1168 if (!ptr) { (gdb) print ptr $1 = 0xbff2d96c "/media/MMC-SD/partition1/aaaaaaaaaaa" (gdb) print &cwd $2 = (char (*)[3500]) 0xbff2d96c (gdb) print strlen(cwd) $3 = 36 (gdb) print "%s",cwd $4 = "/media/MMC-SD/partition1/aaaaaaaaaaa", '\0' <repeats 912 times>, "��O�001\...

C (or any) compilers deterministic performance

Whilst working on a recent project, I was visited by a customer QA representitive, who asked me a question that I hadn't really considered before: How do you know that the compiler you are using generates machine code that matches the c code's functionality exactly and that the compiler is fully deterministic? To this question I ha...

C variable and constant value comparison not matching

if i have a signed char * p; and i do a comparison if( *p == 0xFF ) break; it will never catch 0XFF, but if i replace to -1 it will... if( *p == (signed char)0xFF ) break; will catch ... how come ? is it something with sign flag ? i though that 0xFF == -1 == 255 ...

How to be notified of file/directory change in C/C++, ideally using POSIX

The subject says it all - normally easy and cross platform way is to poll, intelligently. But every OS has some means to notify without polling. Is it possible in a reasonably cross platform way? (I only really care about Windows and Linux, but I use mac, so I thought posix may help?) ...

Is there a way to insert assembly code into C?

I remember back in the day with the old borland DOS compiler you could do something like this: asm { mov ax,ex etc etc... } Is there a semi-platform independent way to do this now? I have a need to make a BIOS call, so if there was a way to do this without asm code, that would be equally useful to me. ...

Rollover safe timer (tick) comparisons

I have a counter in hardware that I can observe for timing considerations. It counts miliseconds and is stored in a 16 bit unsigned value. How do I safely check if a timer value has passed a certain time and safely handle the inevitable rollover: //this is a bit contrived, but it illustrates what I'm trying to do const uint16_t print_in...

making portable code

with all the fuss about opensource projects, how come there is still not a strong standard that enables you to make portable code (i mean in C/C++ not java or c#) everyone is kind of making it's own soup. there are even some third party libs like Apache Portable Runtime. ...

'bad address' error from copy_to_user

I am attempting to copy a custom struct from kernel space to user space. inside user space errno returns 'bad address'. What is the usual cause of a bad address error? if(copy_to_user(info, &kernel_info, sizeof(struct prinfo))) ...

Asynchronous APIs

Hi, When trying to implement a asynchronous API calls / Non-blocking calls, i know a little in a All Plain-C applicaiton I have, i read a about APM(Asynchronous Programming Model) by 'Delegates'. Basically what i want to do is call one API f1() to do a functionality(which takes long time 8-10 seconds), So i call that API f1(), forget a...

bitwise indexing in C?

I'm trying to implement a data compression idea I've had, and since I'm imagining running it against a large corpus of test data, I had thought to code it in C (I mostly have experience in scripting languages like Ruby and Tcl.) Looking through the O'Reilly 'cow' books on C, I realize that I can't simply index the bits of a simple 'cha...

Get mac address for remote computer under NT4 in C

Is it possible to get the mac address for a remote connection under NT4. The remote pc opens a socket connection into the program and I can get the ip address but need the mac. I have tried using SendARP but this doesn't seem to be supported in NT4. ...

Misra standard for embedded software.

Hi I have a requirement to make a large amount of code MISRA compliant. First question: Can somebody to give an estimation for passing well written code for embedded system based on experience. I understand that "well written" is poorly defined and vague so i ask for raw estimation. Second question: Any recommendation for tool that can ...

Hooking into the TCP Stack in C

It's not just a capture I'm looking to do here. I want to first capture the packet, then in real time, check the payload for specific data, remove it, inject a signature and reinject the packet into the stack to be sent on as before. I had a read of the ipfw divert sockets using IPFW and it looks very promising. What about examples in m...

How to determine CPU and memory consumption from inside a process?

I once had the task of determining the following performance parameters from inside a running application: Total virtual memory available Virtual memory currently used Virtual memory currently used by my process Total RAM available RAM currently used RAM currently used by my process % CPU currently used % CPU currently used by my proce...

A good, free resource to learn the fundamentals of C (not C++) development?

Any recommendation for a good, free resource to learn the fundamentals of C (not C++) development covering basic topics such as Algorithms, Control Structures, Functions, Arrays, Pointers, Structures, et cétera? ...

Bit reversal of an integer, ignoring integer size and endianness

Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I have the following code to reverse the bits of an integer: TYPE max_bit= (TYPE)-1; void reverse_int_setup() { TYPE bits= (TYPE)max_bit; while (bits <<= 1) max_bit= bits; } TYPE reverse_int(TYPE arg) { TYPE bit_setter= 1,...