c

Why does the chip control the language to choose

I've asked the question before what language should I learn for embedded development. Most embedded engineers said c and c++ are a must, but also pointed out that it depends on the chip. Can someone clarify? Is it a compiler issue or what? Do chips come with their own specific compilers (like a c compiler or c++ compiler) and that's wh...

C double linked list with abstract data type

Hello, i need in double linked list in C, but it must be for different types. In C++ we use templates for it. Where can i find example in C for double linked list with abstract types items. Thank you ...

Library files in C

Are library files .o or .exe files in C? ...

An example of an embedded project for a single person

I've been trying to wrap my head around embedded. Since I will be self-taught in this specific niche, I realize it will be harder to get a job in the field, so I'm hoping to add a completed project to my resume to prove to potential employers that I've done it and can do it again for them. Can someone suggest a project that I can undert...

Color console in ANSI C?

Is it possible to color the console output in just plain ANSI C? Without an external library? Can this be done in Windows, Linux, or Mac OS X? ...

Why should files be mounted in Linux

Hello, I got an old library which does some manipulation with files on floppy\ CD (transferring the files on network paths). This library has a thread which checks on each second whether the file (e.g. the floppy diskette\ the CD disk) is mounted. Why? What operations can be done only on mounted files? Thanks a lot. ...

sdl setup visual studio 2010

I can not get sdl up and running. I included the include folder, the library folder and here is the code #include <SDL.h> int main() { if (SDL_Init(SDL_INIT_VIDEO)==-1) { return 1; } SDL_Quit(); return 0; } what am i doing wrong? It gives me this error message Error 1 error LNK2019: unresolved external symbol _...

Saving a C struct with a char* string into a file

I'm trying to save a struct with a char* string into a file. struct d_object { int flags; int time; int offset; char *filename; }; The problem is that when doing that I will obviously only save the address of that pointer rather than the string. So what I've done is simply use a character array and but I'm forced to ...

LD_PRELOAD affects new child even after unsetenv("LD_PRELOAD")

my code is as follows: preload.c, with the following content: #include <stdio.h> #include <stdlib.h> int __attribute__((constructor)) main_init(void) { printf("Unsetting LD_PRELOAD: %x\n",unsetenv("LD_PRELOAD")); FILE *fp = popen("ls", "r"); pclose(fp); } then in the shell (do the 2nd command with care!!): gcc prel...

C aliasing rules and memcpy

While answering another question, I thought of the following example: void *p; unsigned x = 17; assert(sizeof(void*) >= sizeof(unsigned)); *(unsigned*)&p = 17; // (1) memcpy(&p, &x, sizeof(x)); // (2) Line 1 breaks aliasing rules. Line 2, however, is OK wrt. aliasing rules. The question is: why? Does the compiler have special...

How to implement a 2-dimensional array of struct in C

Hey *, I'm currently trying to understand how to implement a 2-dimensional array of struct in C. My code is crashing all the time and I'm really about to let it end like all my approaches getting firm to C: garbage. This is what I got: typedef struct { int i; } test; test* t[20][20]; *t = (test*) malloc(sizeof(test) * 20 * 20); M...

Audio detection in an embedded system

I'm getting started with embedded, and was thinking to start learning by implementing some sort of a clapper project where I detect audio and respond to it. I have some specific questions, but since I'm new to this field, please add any additional advice What audio libraries exist that could help with this type of project What hardwa...

Can you decipher the difference between this switch() and an equivalent for()?

This one works as intended: if (clu.raw.butsnum) { int i; for (i=0;i<clu.raw.butsnum;i++){ if (clu.raw.buts[i] & RI_MOUSE_BUTTON_1_DOWN) Com_QueueEvent( 0, SE_KEY, K_MOUSE1, qtrue, 0, NULL ); if (clu.raw.buts[i] & RI_MOUSE_BUTTON_2_DOWN) Com_QueueEvent( 0, SE_KE...

Merge algorithm in C: how does this work?

This C snippet is part of a merge algorithm implementation: out[i++] = (in1[i1] < in2[i2]) ? in1[i1++] : in2[i2++]; Can someone please explain how it works? ...

Are there specialities within the embedded fields

I've started learning embedded and its 2 main languages (c and c++). But I'm starting to realize that despite the simple learning requirements, embedded is a whole world in and of itself. And once you deal with real projects, you start to realize that you need to learn more "stuff" specific to the hardware used in the device you're worki...

gtk+ printing image

Hello, In my C/gtk+ application I have list of images. Where can find simple example for printing those images? Thank you ...

C - read string from buffer of certain size

Hey, I have a char buf[x], int s and void* data. I want to write a string of size s into data from buf. How do I do that? Thanks in advance. ...

Simple C number formatting question

Hi guys, This a very simple c question. Is there a way to format a float for printf so that it has xx SIGNIFICANT decimals? So I'm not take about, say, %5.3 float, but if I had float x=0.00001899383 how would i output 0.0000189 if i wanted UP TO the first three non-zero decimals? thanks! I'm not stating at home this weekend so I do...

C operator priority

How are arithmetic expression evaluated in The C language? How can I understand the Operator priority? ...

fopen fails mysteriously under Windows

Maybe I just have another black out but, this one line is giving me a lot of troubles: FILE *fp = fopen("data/world.data", "rb"); This works fine under Linux when compiled with GCC. But when I compile it with Visual Studio, it crashes. fp is always NULL. Both the BIN and the EXE are in the exact same directory. Now, to make things eve...