Can you define a macro that accesses a normal variable, but in a read-only fashion (other than defining it as a call to a function)? For example, can the VALUE macro in the following code be defined in such a way that the dostuff() function causes a compile error?
struct myobj {
int value;
}
/* This macro does not satisfy the read-on...
I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators) ...
What I'm wondering is, at a core level, what does bit-shifting (<<, >>, >>>) do, what problems can it help solve, and what gotchas lurk around the bend? In other words, an absolute beginner's g...
How do you compare two instances of structs for equality in standard C?
...
My application is generating different floating point values when I compile it in release mode and in debug mode. The only reason that I found out is I save a binary trace log and the one from the release build is ever so slightly off from the debug build, it looks like the bottom two bits of the 32 bit float values are different about 1...
The following snippet is supposed to take the value of PROJECT (defined in the Makefile)
and create an include file name. For example, if PROJECT=classifier, then it should at the end generate classifier_ir.h for PROJECTINCSTR
I find that this code works as long as I am not trying to use an underscore in the suffix. However the use of t...
I'm looking for a piece of code that can tell me the offset of a field within a structure without allocating an instance of the structure.
IE: given
struct mstct {
int myfield;
int myfield2;
};
I could write:
mstct thing;
printf("offset %lu\n", (unsigned long)(&thing.myfield2 - &thing));
And get "offset 4" for the output. ...
Is there a way to get the C/C++ preprocessor or a template or such to mangle/hash the __FILE__ and __LINE__ and perhaps some other external input like a build-number into a single short number that can be quoted in logs or error messages?
(The intention would be to be able to reverse it (to a list of candidates if its lossy) when needed...
I need my code to do different things, based on the operating system it gets compiled on. I'm looking for something like this:
#ifOSisWindows
//define something for Windows
#else
//define it for a Unix machine
#endif
Is there a way to do this? Is there a better way to do the same thing?
...
I am new to C, Objective-C, and Core Audio programming on OSX. From the reading that I have done, Core Audio relies heavily on callbacks (and C++, but that's another story). I understand the concept (sort of) of setting up a function that is called by another function repeatedly to accomplish a task. I just don't understand how they g...
I have a very large codebase (read: thousands of modules) that has code shared across numerous projects that all run on different operating systems with different c++ compilers. Needless to say, maintaining the build process can be quite a chore.
There are several places in the codebase where it would clean up the code substantially if...
struct a
{
char *c;
char b;
};
What is sizeof(a)?
...
I've recently seen the light of EventWaitHandle's powerful behavior in C# and decided to move some functionality in a sister application to do the same. The only problem is that the sister app is written in C.
No big deal, I'm using pthreads, which have a pthread_cond_t datatype that allows for signalling. My only question is, is it pos...
Just as in title. Is suspect it is, but I couldn't find it anywhere explicitly stated. And for this property I wouldn't like to rely on speculations.
...
Using C / C++ socket programming, and the "read(socket, buffer, BUFSIZE)" method. What exactly is the "buffer" I know that char and byte are the same thing, but does it matter how many elements the byte array has in it? Does the buffer need to be able to hold the entire message until the null character?
...
Is there a platform-agnostic and filesystem-agnostic method to obtain the full path of the directory from where a program is running using C/C++? Not to be confused with the current working directory. (Please don't suggest libraries unless they're standard ones like clib or STL.)
(If there's no platform/filesystem-agnostic method, sugge...
I am using cxxtest as the test framework for my C++ classes, and would like to figure out a way to simulate sending data to classes which would normally expect to receive it from standard input. I have several different files which I would like to send to the classes during different tests, so redirection from the command line to the te...
Hi all!
Going back to my previous question on OCSP, does anybody know of "reliable" OCSP libraries for Python, Java and C?
I need "client" OCSP functionality, as I'll be checking the status of Certs against an OCSP responder, so responder functionality is not that important.
Thanks
...
Many claim that, when performance is at a premium, it's sufficient to write and compile C code to get near-optimal code that is additionally quite portable. I don't see much of a assembly/assembler discussion on stackoverflow (about 0,3% of the questions right now are tagged any of those tags, many of which refer to .NET Assemblies).
H...
How do you do your own fonts? I don't want a heavyweight algorithm (freetype, truetype, adobe, etc) and would be fine with pre-rendered bitmap fonts.
I do want anti-aliasing, and would like proportional fonts if possible.
I've heard I can use Gimp to do the rendering (with some post processing?)
I'm developing for an embedded device ...
I realize this is a subject of hot debate, but I'm interested in opinions that relate to my specific situation.
I want to learn the basics and fundamentals of programming, so I'm already taking a college course in general programming concepts. It isn't covering a specific language, but it's giving me a solid foundation that I can build ...