c

Are C/C++ compilers optimizing across compilation units?

Optimizations such as constant propagation are possible across functions within the same compilation unit (ie. same file). For example : int f(int x) { return 3 + x; } void main() { printf("%d", 1+f(4)); } In that example, I think that a sufficiently smart compiler can propagate the '4' constant to the function 'f', solving...

How does compiler know that the function you used is a system call?

For the following snippet of code, int n; char buf[100]; int fd = open ("/etc/passwd", O_RDONLY); n = read ( fd, buf, 100); How the compiler comes to know that read is a system call not any library function? How it retrieves the system call number (__NR_read)? ...

bitwise operations

// PWM frequency: // 0 - 48 kHz // 1 - 12 kHz // 2 - 3 kHz enum { MOTOR_FREQUENCY = 1 }; // Configure Timer 2 w. 250x period. T2CON = 1 << 2 | MOTOR_FREQUENCY /* << 0 */; Have i understood this right? 11111111 Arithmetic left-shift-by-two of 0 or 1 or 2 Means: T2CON = 1 << 2 | 0 = 1111 1100 T2CON = 1 << 2 | 1 = 1111 1000 ...

Linux Kernel Programming for Beginners

I have been working on LINUX for the past six years, and am a core Linux guys since I started my career on Linux. Working more on Redhat / Centos / Fedora based distribution system administration, with some basic bash scripting knowledge. Now I am looking to deep dive into programming to contribute or innovate something new on Linux ope...

How to generate 8 byte hex value?

Hi I want to generate this sequential data in C data_packet[1] = 0706050403020100 (seed_value) next data_packet[2] = 0f0e0d0c0b0a0908 Next will be the next 8 hexadecimal characters and so on for say 100 bytes.How can i do it.Can we do it using character array ?? ...

finding sum,min,max with array

Write a program that inputs number of values then inputs these values (double type) one by one in a loop and finally outputs their sum, the maximum value and the minimum value. I write the code for this assignment but i got error #include <stdio.h> int main(void) { float a; float i; short c; float sum...

C memcpy error - memory could not be written on Windows XP

I have a C program which loads a file line-by-line into one string and then memcpy's this string into another string pointer using this code: typedef struct inmod_struct { Int32 ReturnCode; Int32 Length; char Body[ROWSIZE]; } inmdtyp,*inmdptr; inmdptr inmodptr; char line[600]; int doit() { ...

Multiplying three matrices in BLAS with the middle one being diagonal

A is an MxK matrix, B is a vector of size K, and C is a KxN matrix. What set of BLAS operators should I use to compute the matrix below? M = A*diag(B)*C One way to implement this would be using three for loops like below for (int i=0; i<M; ++i) for (int j=0; j<N; ++j) for (int k=0; k<K; ++k) M(i,j) = A(i,k)*B(...

Is res_query thread-safe?

Is res_query (int res_query(const char *dname, int class, int type,unsigned char *answer, int anslen);) thread-safe? I think so, because it writes its answer to an user-allocated buffer (in contrast to gethostbyname that uses a statically allocated buffer). Does somebody know for sure? ...

Getting around lack of inline asm using MSVC10 x64

I'm trying to write a simple device driver for Windows 7 x64 using the latest Windows Driver Kit that will parse the Interrupt Descriptor Table (IDT) and print the contents. I plan on doing this by using the SIDT (store IDT) assembly instruction, however MSVC does not allow you to use inline asm when compiling for x64. Is there any way t...

Help with endianness?

Hey guys I learned about endianness and am still having difficulty understanding where things could go wrong. I was wondering what sort of things I should look for and how I should go about fixing it. I know I dont need to change anything for loading from text files and things like that but for example here is a snippet of my code for lo...

Java AES encryption with C/C++ AES decryption question

I am doing a simple AES encryption in Java: Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, getAES128SecretKey()); byte[] encrypted = cipher.doFinal(input); The output is converted to hex and stored in a database. A later process (one written in C/C++) comes along and reads the hex, converts it to bytes an...

array gets wiped out

I have a situation where I am writing commands to a command buffer. When it is time for a command in the command buffer to be executed, the command is processed and sent out the UART to another subsystem. When the command is processed, the data that needs to be sent out the UART is stored in a queue and a flag is raised. Then shortly aft...

compiler says:cannot convert int to FILE*

While doing filing im stuck here.The condition of the while loop is not working.The compiler says cannot convert int to FILE*. while(pFile!=EOF); Should i typecase the pFile to int?I tried that but it did not worked.Thanks in advance. The complete code is: int main() { char ch; char name[20]; FILE *pFile; int score; ...

Mouse Interaction

How can I make mouse interaction with c environment in windows platform? ...

Array combinations of 0s and 1s

What is a good algorithm to fill an array with 0s and 1s combinations. For example if I have three columns the combinations would be: (1 1 1) (0 1 1) (1 0 1) (0 0 1) (1 1 0) (0 1 0) (1 0 0) (0 0 0) It makes a total of 8 rows (I hope I'm right here). So how to determine the needed number of rows in advance (depending on the N num...

Best way to assert compatible architecture when reading and writing a file?

I have a program that reads and writes a binary file. A file is interchangeable between executions of the program on the same platform, but a file produced on one machine may not be valid on another platform due to the sizes of types, endian-ness etc. I want a quick way to be able to assert that a given file is valid for reading on a g...

Is main() a pre-defined function in C?

Possible Duplicate: main() in C, C++, Java, C# I'm new to programming in general, and C in particular. Every example I've looked at has a "main" function - is this pre-defined in some way, such that the name takes on a special meaning to the compiler or runtime... or is it merely a common idiom among C programmers (like using ...

How do I use libcurl to login to a secure website and get at the html behind the login.

Hey guys, I was wondering if you guys could help me work through accessing the html behind a login page using C and libcurl. Specific Example: The website I'm trying to access is https://onlineservices.ubs.com/olsauth/ex/pbl/ubso/dl Is it possible to do something like this? The problem is that we have a lot of clients each of which h...

How to store molecules in memory?

I want to store molecules in memory. These can be simple molecules: Methane (CH4) C-H bond-length: 108.7 pm H-H angle: 109 degrees But also more complex molecules, like paracetamol (C8H9NO2): How can I store molecules in memory, including all bond-lengths and angles? A good idea to store atom-structs in an array? Or is there a be...