c

Freeing memory allocated to an array of void pointers

I am declaring an array of void pointers. Each of which points to a value of arbitary type. void **values; // Array of void pointers to each value of arbitary type Initializing values as follows: values = (void*)calloc(3,sizeof(void)); //can initialize values as: values = new void* [3]; int ival = 1; float fval = 2.0; ...

overflows in size_t additions

I like to have my code warning free for VS.NET and GCC, and I like to have my code 64 bit ready. Today I wrote a little module that deals with in memory buffers and provides access to the data via a file-style interface (e.g. you can read bytes, write bytes, seek around ect.). As the data-type for current read position and size I used ...

Does C++ still matter?

I am a CS student currently learning C. I'd like to get into low level programming, whether as a hobby or career and may contribute to some open source projects down the line. So far I really enjoy C and think I will continue down the abstraction level and take ASM next semester. The question I have is this, is knowing C enough to be a...

Pointer question

I am new to C and i have this question. why does the following code crash: int *a = 10; *a = 100; ...

Purpose of _never_executed()?

I have seen this macro defined before but never really knew its purpose. Can anyone shed light on this? ...

Function pointers, Closures, and Lambda

I am just now learning about function pointers and as I was readying the K&R chapter on the subject the first thing that hit me was, "Hey, this is kinda like a closure." I knew this assumption is fundamentally wrong somehow and after a search online wasn't really to find any analysis of this comparison. So why are C style function point...

A C library for finding local maxima?

I'm trying to write an audio analysis application, and I need to identify local maxima in a 2D array which represents a spectrogram. I've already got an open source library that can generate the spectrogram using Fast Fourier Transforms, but I was wondering if anybody knew of any good libraries to help me with actually finding the maxima...

How to start Linux Programming

I am working on C++ and COM/ATL in Windows from last few years. Now I want to shift to Linux Programming. I know basic architecture of Linux. I did some of the projects which are using ncurses, sockets and audio libraries(Terminal Applications). On which tool I should be familiar to start with projects. In windows I have started with Win...

Steps to make a LED blink from a C/C++ program?

What are the easiest steps to make a small circuit with an LED flash from a C/C++ program? I would prefer the least number of dependencies and packages needed. What port would I connect something into? Which compiler would I use? How do I send data to that port? Do I need to have a micro-processor? If not I don't want to use one for ...

Get other process' argv in OS X using C

I want to get other process' argv like ps. I'm using Mac OS X 10.4.11 running on Intel or PowerPC. First, I read code of ps and man kvm, then I wrote some C code. #include <kvm.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/sysctl.h> #include <paths.h> int main(void) { char errbuf[1024]; kvm_t *kd ...

Why does scanf() need "%lf" for doubles, when printf() is okay with just "%f"?

Why is it that scanf() needs the L in "%lf" when reading a double, when printf() can use "%f" regardless of whether its argument is a double or a regular-precision float? Example code: double d; scanf("%lf", &d); printf ("%f", d); ...

stdcall over-ride by visual studio ?

In xp 32bit this line compiles with not problem however in vista 64bit this line: m_FuncAddr = ::GetProcAddress (somthing); gives the following error error C2440: '=' : cannot convert from 'FARPROC' to 'int (__cdecl *)(void)' GetProcAddress is defined as WINBASEAPI FARPROC WINAPI GetProcAddress (somthing) And m_FuncAddr as...

C non-standard libraries

I'm quite new to programming, and I was wondering if there is a good source of well-programmed non-standard C code and libraries. I Googled and didn't find anything. I was a bit surprised by this, especially because I used to search for many Python examples and libraries and never had trouble finding anything. I already use standard l...

Can I use the standard C library in a Palm OS application?

The published code for Palm OS applications doesn't include standard headers, but instead uses Palm OS APIs for things like StrCopy and MemMove. Can I use standard headers and functions or do I need to convert my code to use the Palm OS versions? ...

Fastest way to do a case-insensitive substring search in C/C++?

I need to do a fast case-insensitive substring search in C/C++. My requirements are as follows: Should behave like strstr() (i.e. return a pointer to the match point). Must be case-insensitive (doh). Must support the current locale. Must be available on Windows (MSVC++ 8.0) or easily portable to Windows (i.e. from an open source librar...

What do you miss when you have to use C instead of C++?

This is not a question about which of the two languages is better than the other. I myself can't really decide. Pros and cons as always I guess. Also, if you feel you always would prefer C over C++, this poll is not for you :-). However, when I work in C projects I usually feel I'm missing a few language constructs more than others, wh...

Dynamically Loading External Modules in a C Program?

I'm sure this problem has been solved before and I'm curious how its done. I have code in which, when run, I want to scan the contents of a directory and load in functionality. Specifically, I am working with a scripting engine that I want to be able to add function calls to. I want the core engine to provide very limited functionality....

What is a bus error?

What does the "bus error" message mean, and how does it differ from a segfault? ...

How do you do exponentiation in C?

I tried "x = y ** e", but that didn't work. ...

Boost like libraries in C

Hi, Can you recommend peer reviewed libraries that I can use in C environment (something like Boost for C++) ? Something that provides hash, thread, interprocess communications, lists, smart memory management... The environment is embedded system, not a very minimal system, but also not a PC! Thanks! Amit ...