c

Does c/c++ have a delay function?

Does c/c++ have a delay/wait/sleep function? ...

Does malloc/new return memory blocks from Cache or RAM?

Hi, I wanted to know whether malloc/new returns memory blocks from Cache or RAM. Thanks in advance. ...

C/C++ Libraries for reading from Universal Disk Format devices or files

Are there any good free C/C++ libraries that enable reading from common devices with filesystems such as UDF, and ISO9660 and extracting files/metadata etc.? So far all I've been able to find is GNUs libcdio which is promising, and some "Magic UDF" which has so many hits I'm disgusted, pushes other results in Google, and comes with a pr...

Most tricky/useful commands for gdb debugger

Hi All, Can you post your most tricky and useful commands while you run a debugger like gdb or dbx. ...

This C snippet compiles but does not give the right answer

#include <stdio.h> void main(void) { int i; char c; for (i=0;i <5;i++) { scanf("%d",&c); printf("i=%d\r\n",i); } printf("The loop is finished!\r\n"); } Especially the scanf function... Can you give detailed explanation? ...

What are most useful/used vim commands in C/C++ dev environment

Here is the list of mine Unlike me -- as I did it for illustrative purposes -- don't paste too many. And most importantly, provide an explanation Commands shouldn't be generic but relevant to C++/C environment. ctags & scope are welcome too gi .....................init insert mode in last insertion position '0 ...................

Removing lowest order bit

Given a binary number, what is the fastest way of removing the lowest order bit? 01001001010 -> 01001001000 It would be used in code to iterate over the bits of a variable. Pseudo-code follows. while(bits != 0){ index = getIndexOfLowestOrderBit(bits); doSomething(index); removeLowestOrderBit(bits); } The possible languages I'...

C default arguments

Is there a way to specify default arguments to a function in C? ...

c trimming newline character when reading input from file

Is this a safe way to trim the newline character off of a line after reading it in from a file? while ( fgets(buffer, 1024, fp) != NULL ) { buffer[strlen(buffer)-1] = '\0'; fprintf (stderr, "%s\n", buffer); } It doesn't give me any seg faults but could it cause problems down the road? Should I do something like this instead? ...

Printing chars and their ASCII-code in C

How do I print a char and its equivalent ASCII value in C? ...

Is there a compiler feature to inject custom function entry and exit code?

Currently coding on Windows with VS2005 (but wouldn't mind knowing if there are options for other compilers and platforms. I'm most interested in OSX as an alternative platform.) I have a C (no C++) program and I'd like to do the following... Given a function, say... int MyFunction(int myparam) { // Entry point. ... // Exit ...

Long double datatype problem in C

In the code below, printf prints -0.00000. What is the problem? If it is double instead of long double, then it works fine. #include<stdio.h> long double abs1(long double x) { if (x<0.0) return -1.0*x; else return x; } main() { long double z=abs1(4.1); printf("%llf\n",z); } ...

Building the equivalent of a C structure in RubyCocoa

I'm trying to do something similar to this code sample but in RubyCocoa. In particular, I'm having some trouble trying to build a SecKeychainAttributeList. I suspect I need to make use of Array#pack or something to build a suitable structure in Ruby. Any advice on how to build the equivalent of attributes in the following chunk of code w...

Does a "UDP Client For the TIME Service" need to check the length of the read data before converting?

I'm in the middle of of reading Internetworking with TCP/IP Vol III, by Comer. I am looking at a some sample code for a "TIME" client for UDP. The code gets to the point where it does the read of the response, and it takes what should be a 4 bytes and converts it to a 32 bit unsigned integer, so it can be converted to UNIX time. "n" i...

Avoid casting from volatile static uint8_t to uint8_t in function calls?

I currently have this code: static void func( uint8_t var ); static volatile uint8_t foo; int main() { /* Here we have to cast to uint8_t */ func( (uint8_t) foo ); /* This will not compile */ func( foo ); } Is there a way to avoid the cast in the function call? ...

memory leak debug

What are some techniques in detecting/debugging memory leak if you don't have trace tools? ...

optimizing branching by re-ordering

I have this sort of C function -- that is being called a zillion times: void foo () { if (/*condition*/) { } else if(/*another_condition*/) { } else if (/*another_condition_2*/) { } /*And so on, I have 4 of them, but we can generalize it*/ else { } } I have a good test-ca...

Can the Size of Pointers Vary Depending on what's Pointed To?

I was just reading the section of the C FAQ on pointers. It discusses not being able to use void * pointers to hold function pointers because pointers to data and pointers to functions may have differing sizes on some platforms and void * is only guaranteed be large enough to hold pointers to data. Can anyone give an example of a platf...

Is there a way to figure out the top callers of a C function?

Say I have function that is called a LOT from many different places. So I would like to find out who calls this functions the most. For example, top 5 callers or who ever calls this function more than N times. I am using AS3 Linux, gcc 3.4. For now I just put a breakpoint and then stop there after every 300 times, thus brute-forcing ...

How can I tell gcc not to inline a function?

Say I have this small function in a source file static void foo() { } and I build an optimized version of my binary yet I don't want this function inlined (for optimization purposes). is there a macro I can add in a source code to prevent the inlining? thanks ...