c

unlocked_ioctl vs normal ioctl

In my driver's file_operations structure, I have: struct file_operations Fops = { read: device_read, write: device_write, unlocked_ioctl: device_ioctl, ... }; I.e. there is no ioctl field used. Is this sufficient to avoid Big Kernel Lock and enter into device_ioctl() without any synchronization? Or do I have to change i...

__udivdi3 undefined. Howto find code?

Compiling a kernel module on 32-Bit Linux kernel results in "__udivdi3" [mymodule.ko] undefined! "__umoddi3" [mymodule.ko] undefined! Everything is fine on 64-bit systems. As far as I know, the reason for this is that 64-bit integer division and modulo are not supported inside a 32-bit Linux kernel. How to I find the code issueing th...

Aligned and unaligned memory accesses?

What is the difference between aligned and unaligned memory access? I work on an TMS320C64x DSP, and I want to use the intrinsic functions (C functions for assembly instructions) and it has ushort & _amem2(void *ptr); ushort & _mem2(void *ptr); , where _amem2 does an aligned access of 2bytes and _mem2 does unaligned access. When sh...

Accessing special Data in the PrinterDriver via C (like duplex printing)

moin-moin, I know, I am the only living person, still writing software for OS/2, but maybe someone can give me a hint: For a customer I need to print a lot of different Reports on many pre-printed papers, some one-side, some double-sided, orientation landscaped or portrait (so, there are many different combinations) the option i use n...

Pass and access structures using objective-c

I want to know how to pass structures to another function and subsequently access that structure in the called function. I'm developing for the iPhone and the reason I'm using structs is so that I can eventually pass data as structs to a server being built in C. Here's the structure: struct userInfo{ NSString *firstName; NSStri...

struct initializer, typedef with visual studio

I wonder why the following does not work with Visual studio typedef struct { float x, y; } complexf; typedef union { complexf f; long long d; } rope; int main(void) { complexf a; rope z = {a}; } The error is at line rope z = {a}, cannot convert from complexf to float. If the first member of the union is not a typ...

Scanning variable number of 'fields' from a text file

I'd like to scan a variables that form vectors from white space delimited text file and the stumbling block (all to often for me) is lack of elegance. Currently my scanning code requires delineating the size of the vector as the first element in the file: 7 : 1 3 6 8 -9 .123 1.1 Which bothers me because the '7' could be determined by...

Parsing a string with tokens for the first and last words (in C)

I'm going to try to explain the problem. I am getting a string containing a registry key. For example: HKEY_CURRENT_USER\Software\MyProgram\SomeOtherValue\SomeKey now, I need to parse that string into 3 different char (or char *) variables. After the parsing it'll be something like: string1 = HKEY_CURRENT_USER string2 = \Software\My...

C/C++ initialization of a normal array with one default value

http://www.fredosaurus.com/notes-cpp/arrayptr/array-initialization.html 1: Page above has a nice list over initialization of arrays. So I have a int array[100] = {-1}; expecting it to be full with -1's but its not, only first value is and the rest are 0's mixed with random values. The code int array[100] = {0}; works just fine a...

How to access the default stdin while using file redirection?

I need to run a script and have access to the default stdin (terminal input) in my program. I could do ./program "script", opening and parsing the script through the program, but I want to make it POSIX style, accepting input from pipes or from redirection. I mean, since my program is a parser, I could run ./program, type the script and...

Write a C program to find the smallest of three integers, without using any of the comparison operators.

I found this question online and have been struggling to come up with an answer to it on my own. Bonus question I found. Write hello world in C without using a semicolon. ...

Can I compute pow(10,x) at compile-time in c?

Is it possible to compute pow(10,x) at compile time? I've got a processor without floating point support and slow integer division. I'm trying to perform as many calculations as possible at compile time. I can dramatically speed up one particular function if I pass both x and C/pow(10,x) as arguments (x and C are always constant in...

Can C arrays contain padding in between elements?

I heard a rumor that, in C, arrays that are contained inside structs may have padding added in between elements of the array. Now obviously, the amount of padding could not vary between any pair of elements or calculating the next element in an array is not possible with simple pointer arithmetic. This rumor also stated that arrays whic...

sscanf and strings

Hi I'm parsing some CSV data in C for the purposes of a Ruby extension. In order to pull out the data from each row I'm using sscanf as follows: char* line = RSTRING_PTR(arg); double price; double volume_remaining; unsigned int type_id, range, order_id, volume_entered, minimum_volume, duration, station_id, region_id, solar_syst...

Is C or C++ better for making portable code?

I am trying to have some fun in summer. Writing a piece of code that enables presenting Arabic language in systems that support Unicode but no support for eastern languages it. I am writing only the logic hopefully with no integration code initially. Should I use C++ or C? Which is the easier language to write portable code and easier...

C multi-line macro: do/while(0) vs scope block

Possible Duplicates: Whats the use of do while(0) when we define a macro? Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? do { } while (0) what is it good for? I've seen some multi-line C macros that are wrapped inside a do/while(0) loop like: #define FOO \ do { \ do_stuff_here...

C/C++ testing framework (like JUnit for java)

Been hitting my head on the wall before as I don't make any test classes while using c/c++ (but instead have a lot of print methods). What is the most used method to perform testing in the c/c++ code? Java's JUnit has only left me with good memories while debugging things. I know that using asserts in code with a defined debug header ...

Generate C wrapper from C++?

Hi, I want to generate C wrappers from C++ libraries. There are tutorials on how to do it by hand: http://developers.sun.com/solaris/articles/mixing.html http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html http://yosefk.com/c++fqa/mixing.html But it is too much of a manual labor. For example, for this: struct RtAudio { ...

How to track down cause of missing struct from include files in C?

Hey, I have a rather large project I'm porting, and in one of the MANY headers I've included a file that contains a struct definition for pmc_mdep. (prior in the file its just declared, but later its actually defined). Trying to compile it gives me errors about that struct being an incomplete type (which I believe means that it's lack...

Didn't allocate memory by using malloc

Hi all, I am facing a problem on malloc for allocating memory: ByteArr = (BYTE *)malloc(sizeof(SHORT) * 20); I m getting error like "CXX0030: Error: expression cannot be evaluated" But if i am taking 428 or 1024 instead of 20 than its allocating the memory.Can you please tell me where is the problem ...thanks. ...