I'm writing firmware in C for an embedded processor. I want to have all the configuration information in one header file called config.h. This is causing problems with the ADC initialization, where simple #defines won't do the trick. Right now the code is like so:
config.h
#define NUMBER_OF_POTS 1
#define POT_1_CHANNEL 27
adc.c
#d...
I'm a C Newb
I write lots of code in dynamic languages (javascript, python, haskell, etc.), but I'm now learning C for graduate school and I have no idea what I'm doing.
The Problem
Originally I was building all my source in one directory using a makefile, which has worked rather well. However, my project is growing and I would like ...
I'm writing a code generator, well, actually a data generator that will produce data structures of this form (obviously the actual data structures are much more elaborate):
typedef struct Foo {
int a;
struct Foo* foo;
} Foo;
extern Foo f1;
extern Foo f2;
Foo f1 = {1, &f2};
Foo f2 = {2, &f1};
This is portable for all C and C++ co...
I visited a university CS department open day today and in the labs tour we sat down to play with a couple of final-year projects from undergraduate students. One was particularly good - a sort of FPS asteroids game. I decided to take a peek in the src directory to find it was done in C++ (most of the other projects were Java 3D apps).
...
**C Newbie Alert** How does one set the "Description" property of an executable? By this I mean the value displayed when you right-click an executable in Windows Explorer and it shows "Description:" with what seems to be just the name of the executable without the file extension.
I'm running GCC 3.4.5 (mingw-vista special r3) on Window...
I'm new to python. I've studied C and I noticed that that the C structure (struct) seemed to have the same task as "class" in python. So what is, conceptually, the difference?
...
Guys, would you describe a few things about c++ building blocks, on unix.
I want to create an application that links against static libs and dynamic libs (.so).
Question 1: How do I create static library using gcc/g++ ?How do I make my app link against it.
Question 2: How to specify it in the makefile, linking against static and dy...
I'm writing a straightforward C program on Linux and wish to use an existing library's API which expects data from a file. I must feed it a file name as a const char*. But i have data, just like content of a file, already sitting in a buffer allocated on the heap. There is plenty of RAM and we want high performance. Wanting to avoid...
For example, I recently came across this in the linux kernel:
/* Force a compilation error if condition is true */
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
So, in your code, if you have some structure which must be, say a multiple of 8 bytes in size, maybe because of some hardware constraints, you can...
I'm starting a new project and decided that I should give this unit testing thing that everybody keeps talking about a try.
The project is a set of C libraries (so no UI or user interaction testing is necessary) and aimed at being cross platform, with Linux, FreeBSD and Windows being my first priority and OS X planned once the first r...
I'm a very frequent user of the GNU autotools (mostly autoconf, occasionally libtool). I'm working on a project where portability is going to be a sticking point .. yet the rest of the team is just not comfortable working with M4. I got this in my inbox from not one, but four people:
Anyway, perhaps someone could recommend something P...
I have code like this, and I find it a bit hard to read:
// code1
if( (expensiveOperation1() && otherOperation() && foo())
|| (expensiveOperation2() && bar() && baz()) {
// do something
}
I just changed it to the following, to make it more readable:
// code2
const bool expr1 = expensiveOperation1() && otherOperation() && foo(...
I am trying to experiment with expanding paint-like program adding custom features to it. Can you suggest a simple open source paint-like program written in C and using GTK+ library which I could expand? It should compile in Linux but also in Windows (using MinGW). Thanks.
EDIT:
I found this and it looks like something I was looking fo...
I have been studying Java for a few months and am now starting to learn C.
I am a little confused, I was under the impression that passing an object by reference and passing a pointer to that object were the same thing: I thought the difference was that in Java all passing of objects is done with pointers automatically, where as in C o...
I currently have some C code that uses sigaction to associate a handler to the SIGALRM signal. Then I do alarm(TIME_OUT_IN_SECONDS). Problem is, I need milliseconds, not seconds and alarm takes an integer. How can I set the signal to fire off in milliseconds?
...
HI All i'm completing a sample Project(WPF) to show my boss but i need a feature to finish it.
I have a Login Window to authenticate and access in the software now i wish put this LoginWindow as STArtThread so if the user can authenticate(with right password and username) automatically the LoginWindow disappear and can access to use the...
Hi,
Assuming that I have an array of int T,
I am looking for an in-place algorithm that permute i and T[i]
I have : [3 2 0 1] (a)
I want : [2 3 1 0] (b)
eg. in (b) T[0] = 2 because, in (a) T[2] was equal to 0.
I was expecting to find a simple O(n) time, O(1) space algorithm, but I can't find it. Any ideas ?
Note :
There is one ...
Does protection flag affect the sharing between processes? If I have PROT_READ|PROT_WRITE -protected mmapped memory region, is it still fully shared as long as I haven't written into it?
int prot = PROT_READ|PROT_EXEC;
image = mmap(NULL, filesize, prot, MAP_PRIVATE, fildes, 0);
vs:
int prot = PROT_READ|PROT_WRITE|PROT_EXEC;
image = m...
Hi All,
I asked a couple of questions a while ago which have fed into this one, influencing what I want to do with my spare time:
What Language to learn to give me something different to C#
What Masters Programs are looking for
Aside from the basics, I know very little C. I want, and need, to know more C in order to be more successfu...
I have a (somewhat) large truth table / state machine that I need to implement in my code (embedded C). I anticipate the behavior specification of this state machine to change in the future, and so I'd like to keep this easily modifiable in the future.
My truth table has 4 inputs and 4 outputs. I have it all in an Excel spreadsheet, and...