c

how do I make a portable isnan/isinf function.

I've been using isinf,isnan functions on linux platforms which worked perfectly. But this didn't work on osx, so I decided to use std::isinf std::isnan which works on both linux and osx. But the intel compiler doesn't recognize it, and I guess its a bug in the intel compiler according to http://software.intel.com/en-us/forums/showthread...

Unable to locate the Bug

I was recently on The Daily WTF when I came across this old post. In it the author mentions that one of the programmers changed this code: int main (int argc, char **argv) { int x; char data_string[15]; ... x = 2; strcpy(data_string,"data data data"); ... } To this code: int main (int argc, char **argv) { int x = 2;...

FreeRTOS configTICK_RATE_HZ problem

Hi, I am using an MSP430f5438 with version 5.4 of FreeRTOS. I am having a funny problem that I can't figure out. Basically, when I set configTICK_RATE_HZ to different values, the LED blinks faster or slower; it should stay the same rate. It blinks slower the higher i set configTICK_RATE_HZ, and faster when I set TICK_RATE lower. vTas...

C / C++ : Portable way to detect debug / release ?

Is there a standardized (e.g. implemented by all major compilers) #define that will allow me to distinguish between debug and release builds? ...

Could browsing the PHP source code help a PHP developer learn C?

I've started checking out the source code for PHP. I have just started trying to learn C, and since I have a good working knowledge of PHP, would dissecting typical functions I use daily be of great benefit? Or is this likely to be too in-depth for a C beginner? Also, where are most of the functions defined in that source I linked to a...

Unable to recognize single line comments in Lex

Am learning lex in this process, I'm generating tokens for the C language, and am trying to recognize single line comments "//", but am having a conflict with the division operator [1-9][0-9]*|0x[0-9a-fA-F][0-9a-fA-F]* return NUMBER; [a-zA-Z][a-zA-Z0-9]* return IDENT; / ...

how to get bit by bit data from a integer value in c?

i want to extract bits of a decimal no. for example 7 has a binary 0111 and i want to get 0 1 1 1 all bits stored in bool how can i do so? OK loop is not a good option can do some this else to this? ...

Explanation of how stacks work in C

I am just wanting a simple explanation of the linking process when pushing data onto a stack. I know how to build on using the code from my book, but I am not really sure I understand how the process works when you move the stack head link from one to the next. For stacks like: typedef struct node { void dataptr; struct node* l...

Getting weird crashes in mixed fortran/C program

I am trying to replace some graphics code in a set of fortran programs (not my own code). I got one of the simpler ones ('psvdraw') to work just fine, replacing the fortran postscript-generating code with C calls that call the Cairo library (graphic_output.c). I have been able to successfully work out the cross-language calls without t...

How to add n bytes in 64 bit system

Hi, I am working in 64 bit x_86 64 bit OSX system. I am reading the file of legacy database. It is loaded to a memory block and using offsets it read to the structures. It is written in 32 bit mode. So in order to read properly in 64 bit mode, I want to add n bytes to the base address of a structure. Since pointer incement increment...

Is there a way to dump a C struct?

I've written a program to probe the limits of a system's C time.h functions and dump them out in JSON. Then other things which depend on those functions can know their limits. # system time.h limits, as JSON { "gmtime": { "max": 2147483647, "min": -2147483648 }, "localtime": { "max": 2147483647, "min": -2147483648 }, "mktim...

using the 'rm' command in a c program using the system() function in stdlib.h

i am trying to use the rm command in the main routine for deleting a file that i have taken a command line argument. The value is stored in argv[2] i have tried using system("rm argv[2]"); system("rm ./argv[2]"); system("rm $HOME/argv[2]"); But it gives me an error saying "cannot locate file argv[2]" The filename is stored in argv...

Interpretation of int (*a)[3]

When working with arrays and pointers in C, one quickly discovers that they are by no means equivalent although it might seem so at a first glance. I know about the differences in L-values and R-values. Still, recently I tried to find out the type of a pointer that I could use in conjunction with a two-dimensional array, i.e. int foo[2]...

What c lib to use when I need to parse a simple config file under linux?

Hi Let's say I have a simple config file that my c program needs to read/parse. Let's say it looks a little bit like this: #Some comment key1=data1 key2=data2 Is there a standard c lib that I can use instead of writing my own parser? Thanks Johan Note: Today I have my own little parser, but there must be some standard libs that...

Using MS Visual C++ to make a Windows Forms Application in C?

I'm learning C, and I want to use the Windows Forms tools in Visual C++, so I can do Rapid Application Development with C. I've tried changing the compiler mode to C, but then, I can't use the RAD tools in VC++, it seems. ...

Contiguous block of memory with malloc

I'm trying to create a contiguous block of memory in one function call that has the first part of the memory as pointer arrays to the other blocks. Basically, I'm trying to do: int **CreateInt2D(size_t rows, size_t cols) { int **p, **p1, **end; p = (int **)SafeMalloc(rows * sizeof(int *)); cols *= sizeof(int); for (end ...

Regarding stack reuse of a function calling itself?

if a function calls itself while defining variables at the same time would it result in stack overflow? Is there any option in gcc to reuse the same stack. void funcnew(void) { int a=10; int b=20; funcnew(); return ; } can a function reuse the stack-frame which it used earlier? What is the option in gcc to reuse the same...

function to return the windows installed drive ?

i would like to know the function which returns the drive where the windows has been installed. for example if we run a program with following code in windows which is installed in "C:\" temp_char = getWindowsInstalledDrive(); should return "C:\". please point me to that function if you know. it should be a C/C++ function. Thanks...

Can the stack size be changed dynamically - How?

Can the stack size be changed dynamically in C? If yes, How? ...

Received UDP packet length

How to get the length of received UDP packet? Using wireshark I could see the correct length of datagram. How can I print this value in my simple udp server program? I am receiving binary data (Non printable ascii characters as a data) So I can not use strlen(buf) which throws incorrect length. if (ret=recvfrom(s, buf, BUFLEN, 0, ...