I've faced three separate situations in C lately that I would assistance on:
My C code has a global variable:
int ref_buf; //declared in a header file
In a function definition I use the same name as a parameter:
void fun(int ref_buf, param2, param3)
{
}
Will it overwrite the originally defined global variable and will it cause b...
Hi...
I did an application that create a partintion and format the disk using system calls...
In the middle of the process there is a query asking to type the size of the disk... What can i do in my application in order to automaticly answer that query??
can you please help me?
...
I would like to upload a fiel (a picture in my case) in C/C++ using HTTP with libcurl.
It will be great to have a working sample in C/C++ with (optional) the php code for the server side.
...
I'd like to implement an "assert" that prevents compilation, rather than failing at runtime, in the error case.
I currently have one defined like this, which works great, but which increases the size of the binaries.
#define MY_COMPILER_ASSERT(EXPRESSION) switch (0) {case 0: case (EXPRESSION):;}
Sample code (which fails to compile).
...
I was doing an exercise for university where I had to return a value with exit, that value was actually a count of something. This could be above 255 (which exit() can't handle) but the teacher suggested to use test data where the count could never go above that value.
After all this, I needed to handle this count value, the exit status...
I've seen this pattern used a lot in C & C++.
unsigned int flags = -1; // all bits are true
Is this a good portable way to accomplish this? Or is using 0xffffffff or ~0 better?
...
This may seem like a simple question but i am getting an error when compiling this. I want to be able to pass an enum into a method in C.
Enum
enum TYPES { PHOTON, NEUTRINO, QUARK, PROTON, ELECTRON };
Calling the method
makeParticle(PHOTON, 0.3f, 0.09f, location, colour);
Method
struct Particle makeParticle(enum TYPES type, float...
My question is, what does this code do (from http://www.joelonsoftware.com/articles/CollegeAdvice.html):
while (*s++ = *t++);
the website says that the code above copies a string but I don't understand why...
does it have to do with pointers?
...
This is the well know select algorithm. see http://en.wikipedia.org/wiki/Selection_algorithm.
I need it to find the median value of a set of 3x3x3 voxel values. Since the volume is made of a billion voxels and the algorithm is recursive, it better be a little bit fast.
In general it can be expected that values are relatively close.
Th...
I am interested in writing a driver for my Broadcom NDIS ADSL modem.
Given that I have knowledge in C and C++, what tool are needed for this job?
...
I am looking for a library to read meta data from compressed and uncompressed audio files (i.e. mp3, ogg, etc.). In the past I have used libvorbis and id3lib, but I'm wondering if there are better libraries around? Ideally I would like a library that provides a common API to reading meta data from all the various formats. I realize more ...
If I wanted to modify or add my own extensions to C, and add them to the GCC C compiler, what would I need to do? I do not want to propose changes to the language, I want to know how the C compiler actually works.
I've had a look at the source code to GCC and it looks as if Objective-C is implemented as a simple parser that generates co...
I want to set a FourCC value in C++, i.e. an unsigned 4 byte integer.
I suppose the obvious way is a #define, e.g.
#define FOURCC(a,b,c,d) ( (uint32) (((d)<<24) | ((c)<<16) | ((b)<<8) | (a)) )
and then:
uint32 id( FOURCC('b','l','a','h') );
What is the most elegant way you can think to do this?
...
memcmp C implementation - any logical errors with this one?
I was going looking for an implementation of memcmp(), I found this code snippet, but it is clearly marked that there is 1 logical error with the code snippet. Could you help me find the logical error.
Basically, I tested this code against the string.h library implementation o...
Question
I have two compilers on my hardware C++ and C89
I'm thinking about using C++ with classes but without polymorphism (to avoid vtables).
The main reasons I’d like to use C++ are:
I prefer to use “inline” functions instead of macro definitions.
I’d like to use namespaces as I prefixes clutter the code.
I see C++ a bit type safe...
Hi all, I'm trying to write a program that reads text from external file (string string int, per line).
Struct is defined outside of main function:
typedef struct Person {
char fname[15];
char lname[20];
unsigned long int birth;
} clovek;
I don't need "clovek" to be an array as with every line data can be overwritten.
Line is re...
It seems that Python 2.6.1 doesn't compile bz2 library by default from source.
I don't have lib-dynload/bz2.so
What's the quickest way to add it (without installing Python from scratch)?
OS is Linux 2.4.32-grsec+f6b+gr217+nfs+a32+fuse23+tg+++opt+c8+gr2b-v6.194 #1 SMP Tue Jun 6 15:52:09 PDT 2006 i686 GNU/Linux
IIRC I used only --prefi...
Hi,
as a C newcomer I'm a bit confused about bidimensional arrays.
If I want to represent a matrix of 3 rows and 5 columns, I guess the correct declaration is:
char a[3][5];
So, is this an array of 3 pointers to 5 arrays of chars or what?
How come whenever I try to cycle through it like the following it seems to read the wrong resul...
I am profiling the booting process of power PC board, what is the simplest way to profile the booting sequence ?
My first idea is to modify the u-boot/kernel code add printf/printk (using realtime device as reference) and print them on the console. However just printing them on the console may affect the time.
Any thoughts?
Regards,
...
I am aware of GCC's builtin atomic operations: http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Atomic-Builtins.html
But this list doesn't include very simple operations like load and store. I could implement these on limited architectures with inline assembly (in fact for many like x86 they will be basically just regular mov's), but is ther...