c

How to write header files for Devices

I am new to Embedded Programming, taking courses on it. And working with ATSTK600. I am looking for some help on "how to write header files for Devices". Well, to be specific, what are the standard to be followed while writing header files like naming a register, etc (how to create .h & include, that I know). Recently, I got an assignm...

Implicit Declaration of Function in C UNIX

In the following code, I get a warning that there is an implicit declaration of function getpgid. I know its only a warning, but its for a class and the professor wants us to treat warnings as errors. So, help please. I have included the appropriate header file as well so I have no idea whats wrong: #include <unistd.h> pid_t pid, pgi...

How to read a input file with both argv and redirection from a input file

Hi experts, My program needs to accept three kinds of input commands below: ./Myprogram input.txt ./Myprogram < input.txt ./Myprogram I'm thinking about using argc to check the number of arguments to resolve the first two situations (since redirection doesn't count as an argument). But then I stuck on the last case, which simply wait...

Opaque C structs: how should they be declared?

I've seen both of the following two styles of declaring opaque types in C APIs. Is there any clear advantage to using one style over the other? Option 1 // foo.h typedef struct foo * fooRef; void doStuff(fooRef f); // foo.c struct foo { int x; int y; }; Option 2 // foo.h typedef struct _foo foo; void doStuff(foo *f); // fo...

How to write a 24 bit message after reading from a 4-byte integer on a big endian machine (C)?

I am constructing a message to send a 24-bit number over the network. For little endian machines, the code is (ptr is the pointer to the message buffer): *ptr++ = (num >> 16) & 0xFF; *ptr++ = (num >> 8) & 0xFF; *ptr++ = (num) & 0xFF; (So if num0, num1, num2 and num3 are the individual bytes making up num, the message would be e...

Precedence of -D MACRO and #define MACRO

If I have a C file foo.c and while I have given -DMACRO=1 as command line option for compilation. However, if within the header file also I have #define MACRO 2 Which of these will get precedence? ...

How will this Ocaml type definition look in its C stub?

I've taken the following code from http://www.ocaml-tutorial.org/data_types_and_matching I've been trying to write a C stub for following, to invoke from our PHP codebase. I can't quite understand how (and if) I'm supposed to create a typedef for the following Ocaml type expr, and how I can access the function multiply_out from the C st...

Initialization of a pointer array

Hi all, I'm facing a problem initializing an array with pointers to members of a structure. The structure members have to be accessed through a structure pointer. The reason for this is we initialize the pointer at runtime to a memory mapped address location. The following code snippet is an example of the problem; #include <stdio.h> ...

[C] check input for UTF-8, count characters, use regular expressions

Hi, I want to write a C-programm that gets some strings from input. I want to save them in a MySQL database. For security I would like to check, if the input is a (possible) UTF-8 string, count the number of characters and also use some regular expressions to validate the input. So my question is the following: Is there a library that ...

Generate Random number between two number with one rare number..

Hi all, i can generate random number between two numbers in c using this.. arc4random()%(high-low+1)+low; then now my requirement is...i want to make a number rare....thats mean if high=5, low=1, and rare=3, than 3 will be appeared much rarely than 1,2,4 and 5... Thanks ...

Semaphore Syncing

I have two semaphores x (initially at 1) , and y (initially at 0). My thread function code is somewhat like this: ... wait(x); //setting some vars signal(x); wait(y); ... I want to ensure that the threads wait on y in line, ie. if the first thread completed the x-guarded section first, it should get to wait on y first, & so on....

How to fetch memory in realtime after CreateProcess?

I have executed a process using CreateProcess, but I want to fetch or dump the memory area allocated to the process, preferably in real time. Unfortunately I do not know how to recieve the pointer to the memory are after creating the process. I've been searching around, but I have not found any useful answers so far. If anyone could hel...

Print union of two linklist without modify them and change append()

/*Task: Two ordered linklist contain number. eg.1->2->3-> and 2->3->5 **Print** union of them eg.1->2->3->5 ,remove duplication, can't change linklist Problem : 1. append() might need to be modified. 2. dnot't know how to use append() to complete the task. */ #include <stdio.h> #include <malloc.h> #include <s...

remote methode invocation for c

Is there any equivalent middleware for c like rmi for java or .net for c#? ...

Wait & Signal order

If the following pieces of code execute in the order in which I have put them, can I be sure that thread 1 is awoken first by thread 3, later followed by thread 2? main: sem_init(&x,0,0); thread 1: sem_wait(&x); thread 2: sem_wait(&x); thread 3: sem_post(&x); ...

Put breakpoint on named function

Is there a way to put a breakpoint on any function in Visual Studio, sort of like bm kernel32!LoadLib* in WinDbg? I know one way is to break at application start, find the required DLL load address, then add offset to required function you can get via Depends, and create a breakpoint on address. But that's really slow, and switching to ...

Problem with Makefile

Hi, Using the command "make apps", I wanna generate two executables: main_test.exe and main_app2.exe. For some reason, the command to generate main_test.exe is more is less completley ignored when I run the makefile. Finally, I end up with a main_app.exe and main_app2.exe file but there is no main_test.exe file produced. Anyone an idea ...

how to embed C code in python program?

i want to write a program using multi-threading, raw sockets, to scan the ports in python i have a C code for injection of raw socket. i want to perform a ACK scan so need a raw socket. So please help me. thank you ...

expanding va_list portably

I have a 3rd party function with signature: int secretfoo(int numargs, ...); I can call it directly, but what I really want is wrap it with my function that adds some extra arguments to it. Assume simple case of integers: I want calls secretfoo(2, 10, 20) to be translated as this: when I see argument 10 to duplicate it and make the c...

Value of uninitialized semaphore

With reference to the semaphore implementation of semaphore.h in Linux, does an uninitialized semaphore sem_t default to 0? I just discovered that I had forgotten to initialize my semaphores to 0. Even so, the program worked fine without sem_init. (To all the purists, I completely agree that doing so is a bad practice.) ...