c

Writing atomic function

Hi, I want to implement an atomic function in C language, so that the process or thread will not be preempted while executing the function. ...

Why does pointer to malloc'd area fail unless copied?

I have a pointer to a struct. I call a routine that determines whether I need this struct and allocates space for it using malloc, returning the pointer to that area or zero if unused. struct node *node_p; node_p = need_this(); This works and I can properly access all the elements of the struct. One of the elements of struct node is *...

C strings, strlen and Valgrind

Hi everybody, I'm trying to understand why Valgrind is spitting out : ==3409== Invalid read of size 8 ==3409== at 0x4EA3B92: __GI_strlen (strlen.S:31) whenever I'm applying strlen on a dynamically allocated string? Here is a short testcase : #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *hello ...

Dereferencing type-punned pointer will break strict-aliasing rules

Hi there, I used the following piece of code to read data from files as part of a larger program. double data_read(FILE *stream,int code) { char data[8]; switch(code) { case 0x08: return (unsigned char)fgetc(stream); case 0x09: return (signed char)fgetc(stream); case 0x0b:...

Programming rs232 to lcd (Linux)

Hello everyone, I'm using a pc1602f PowerTip directly connected to the PC parallel port using this scheme: http://www.beyondlogic.org/parlcd/parlcd.htm All well as energizes the LCD and shows me the front row with black blocks, until then fine but now I want to send information through the parallel port. If you look at the page you wi...

Parsing .c/.cpp/.py source files in Python to get a list of the functions contained

I'm trying to learn about parsers, for Python, C and C++ source (on my own, not for a school project). Here is a summary of what i want to do: 1) read .c/.cpp/.py source files in Python 2) get a list of all the functions in the source files, and the span of their definitions in terms of line numbers. So to illustrate my question, con...

Accessing scratch pad memory from C

Hi, That might be a little bit an exotic problem, but I hope somebody can still help me out a bit ;). I would like to execute a standard C program, however, at some point during program execution I would like that a certain number of instructions, which are stored in a local scratch pad RAM, are executed. The scratchpad memory i...

C multiple single line declarations

What happens when I declare say multiple variables on a single line? e.g. int x, y, z; All are ints. The question is what are y and z in the following statement? int* x, y, z; Are they all int pointers? ...

Can I increase int i by more than one using the i++ syntax?

Hi int fkt(int &i) { return i++; } int main() { int i = 5; printf("%d ", fkt(i)); printf("%d ", fkt(i)); printf("%d ", fkt(i)); } prints '5 6 7 '. Say I want to print '5 7 9 ' like this, is it possible to do it in a similar way without a temporary variable in fkt()? (A temporary variable would marginally decrease efficiency...

How to measure program execution time in ARM Cortex-A8 processor?

Hi Guys, I'm using an ARM Cortex-A8 based processor called as i.MX515. There is linux Ubuntu 9.10 distribution. I'm running a very big application written in C and I'm making use of gettimeofday(); functions to measure the time my application takes. main() { gettimeofday(start); .... .... .... gettimeofday(end); } This method was ...

How to print the contents of a doubly-linked list?

How can I print the list values using list.h defined in /include/linux/list.h? ...

How to implement puts() function?

I have tried to implement the puts function.It in actual returns a value but i cant get what should it return.please check my code and guide me further /* implementation of puts function */ #include<stdio.h> #include<conio.h> void puts(string) { int i; for(i=0; ;i++) { if(string[i]=='\0') { pri...

What's the difference between libs under Debug/ and Release/ directory in C?

When I link to the one under Release/ ,got a fatal error: LINK : fatal error LNK1146: no argument specified with option '/machine:' Then I tried to link to the .lib under Debug/ and this time it works. But what can be different? ...

Why does the C standard leave use of indeterminate variables undefined?

Where are the garbage value stored, and for what purpose? ...

2dstrings and strncmp

After i input 10 names ,I have to print all the names that start from A .its not printing anything #include<stdio.h> #include<conio.h> #include<string.h> void main(void) { int i; char names[10][50]; printf("Enter 10 names:\n"); for(i=0;i<10;i++) { printf("Enter name %d\n",i+1); gets(names[i]); } ...

Memory Allocation

I used the memory allocation code in a C file and I didn't free it, then the file was deleted. My question is: does a memory leak occur even after the file is deleted without freeing, knowing that the memory of the partition that contains the OP and the programs keeps running out of memory and I have already used "Disk Cleanup"? Note: S...

Flash memory data format

I'm looking for a storage library for storing data in flash memory in an embedded system. I'm on the verge of writing a custom one for want of a format with the right mix of features and simplicity. Ideally it would be a format and C/C++ library with something better than storing raw structures, but less complex than a full blown file s...

weird stack corruption due to a dll call

I'm trying to make a call to a DLL function (via GetProcAddress etc) from C, using lcc compiler. The function gets called and everything goes well, but it looks like the top of the stack gets corrupted. I've tried to play with calling conventions (__stdcall / __cdecl), but that didn't help. Unfortunately I don't have access to the dll c...

write program to perform sum = 1+ (1+2) + (1+2+3) + ... + (1+2...+n)

I can't get the codes right. Can somebody help? #include<stdio.h> int main() { int n, sum,i,j; printf("Please enter an integer, n = "); scanf("%d", &n); for(i=1;i<=n;i++) for(j=1;j<=i;j++) sum = sum + n; printf("sum = %d", sum); return 0; } ...

Strange SIGABRT error.

Hi, I was trying to make a program but, when add sprintf to the equation, I get the following error: Program received signal: "SIGABRT" My sprintf is written as follows: int i; int g; char b[6]; sprintf(b, "%d", i*g); If you need to see the whole code here it is (but you probably don't, just in case though): #include <stdio.h>...