c

How can I perform pre-main initialization in C/C++ with avr-gcc?

In order to ensure that some initialization code runs before main (using Arduino/avr-gcc) I have code such as the following: class Init { public: Init() { initialize(); } }; Init init; Ideally I'd like to be able to simply write: initialize(); but this doesn't compile... Is there a less verbose way to achieve the same effect?...

WIN32 memory issue (differences between debug/release).

I'm currently working on a legacy app (win32, Visual C++ 2005) that allocates memory using LocalAlloc (in a supplied library I can't change). The app keeps very large state in fixed memory (created at the start with multiple calls to LocalAlloc( LPTR, size)). I notice that in release mode I run out of memory at about 1.8gb but in debug i...

Creating dynamically loaded Linux libraries using Eclipse

I am writing a program in C++ using Eclipse. I want to compile it as a library for Linux, somthing like a DLL in Windows. How I can do this? Do you know any tutorials on how libraries are created? I just want to understand that is the analog of a DLL for Linux and how to create it. I will be thankful for a small example. ...

Confused about C macro expansion and integer arithmetic

I have a couple of questions regarding the following snippet: #include<stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]); return 0; } Here the output of the code does not print the array eleme...

How to give input to a windows application programmatically?

Hi Gurus, This is with reference to the below question http://stackoverflow.com/questions/924289/how-to-read-output-and-give-input-to-a-program-from-c-program I found the answer to the above question very usefull. In the same way can I do it for windows applications. Like can I give input into a windows form(like .net, C# applications...

C project structure - header-per-module vs. one big header

I've worked with a number of C projects during my programming career and the header file structures usually fall into one of these two patterns: One header file containing all function prototypes One .h file for each .c file, containing prototypes for the functions defined in that module only. The advantages of option 2 are obvious t...

How do you check if a pointer, in C, is of a certain type?

How do you check if a pointer is of a certain type? Using sizeof is not sufficient. I am trying to avoid putting id-numbers into my structs to identify their type. The assumption is that maybe gcc puts a struct definition somewhere in the process, and maps the definition to the allocated memory at a pointer. If this is true, I'd think ...

strcpy... want to replace with strcpy_mine which will strncpy and null terminate

the clue is in the title but basically I've inherited some code which has 800+ instances of strcpy. I want to write a new function and then to replace strcpy with strcpy_mine. So I'm trying to work out what parameter list strcpy_mine will have. I tried: void strcpy_mine( char* pTarget, const char* const pCopyMe ) { const unsigned i...

Where can I find API documentation for Windows Mobile phone application skin?

I have to customize the look of Windows Mobile (5/6) dialer application. From bits and pieces of information and the actual custom skin implementations in the wild I know that it is actually possible to change a great deal. I am looking for ways to change the look and feel of the following screens: Actual dialer (buttons, number displa...

What good IDE's are availble for C?

So, I found out that one of my courses for the next term have C knowledge as a requirement leaving me to start learning C from the scratch (altough a bit familiar with the C-syntax through C#) and I'm looking for a good IDE to write in. I've never used any other IDEs than Visual Studio and Eclipse for respectively VB/C# and Java, and I'v...

Why sizeof() differs on 64bit cpu ?

Hello Consider following example: #include <stdio.h> #include <inttypes.h> struct A { uint32_t i1; uint32_t i2; uint32_t i3; uint64_t i4; uint32_t i5; uint32_t i6; uint32_t i7; uint64_t i8; uint32_t i9; }; struct B { uint32_t i1; uint32_t i2; ...

Building a project with files pending on a parameter

I am trying to find a way to build a C/C++ project to only include certain files depending on an input i.e, if its parameter a include files 1-5. parameter b include files 6-10, etc etc. Basically a script or something to build a project based off of an input for visual studio. Only ideas I have came up with is using preprocessor comma...

Using callback functions for error handling in C

Hi, I have been thinking about the difficulty incurred with C error handling.. like who actually does if(printf("hello world")==-1){exit(1);} But you break common standards by not doing such verbose, and usually useless coding. Well what if you had a wrapper around the libc? like so you could do something like.. //main... error_catch...

Passing a pointer to an array in a different function in C

Ok, so I am trying to pass a pointer rgb that is initialized with memset to 0 and then looped through to place a 32 bit integer only in the bounds that I create with height and width input (h and w) as well as offset from the top left corner of the 2d array (x and y). after compiling, I seem to have the value with printf of the pointer ...

fscanf - using too long string

char first[10]; char second[10]; What does fscanf(fr,"%s %s\n",first,second); do when first string is too long? can I use just char *first without malloc? and the pointer will show to the string? ...

Reading a Unicode file in C and passing contents as ASCII via sockets

Hey, I've being trying to figure this out, but nothing seems to work. We have an application that reads thousands of transactions files using the normal "fopen fgets etc", which we parse using normal C functions "strstr, strchr, etc" and return back a normalized char *. However, now we need to read some files that are in Unicode (from ...

Should I explicitly cast malloc()'s return value?

I wanted to ask about the following case: char *temp; temp=malloc(10); Since the return type of malloc is void, will the pointer returned by the malloc be implicitly cast to char type before being assigned to temp? What does the standard say in this regard? If our pointer variable is some struct type for ex. struct node *temp; temp...

Disable gcc warning for incompatible options.

I'm curious if there is an option to disable gcc warnings about a parameter not being valid for the language being compiled. Ex: cc1: warning: command line option "-Wno-deprecated" is valid for C++/Java/ObjC++ but not for C Our build system passes the warnings we have decided on globally across a build. We have both C/C++ code and t...

who is responsible for determining the size of the stack

Recently I made a program in c, which only purpose was to overflow the stack, using a recursive method. Apparently there is no portable way(like a try / catch block, at least in c), to avoid that the next call to a function causes a stack overflow. My question is, in your opinion, high-level languages should offer alternatives on resizin...

char * str = (char*) malloc( ) Crash help!

Hello guys, I have this code snippet below and it crashes during the assignment in 'str', a dynamic allocation. char *str; int file_size; FILE *fptr; if (!(fptr = fopen(filename, "r"))) goto error1; if ((fseek(fptr, 0L, SEEK_END) != 0)) goto error2; if (!(file_size=ftell(fptr))) goto error2; if ((fseek(fptr, 0L, SEEK_SET)...