c

Memory access violation. What's wrong with this seemingly simple program?

This is a quick program I just wrote up to see if I even remembered how to start a c++ program from scratch. It's just reversing a string (in place), and looks generally correct to me. Why doesn't this work? #include <iostream> using namespace std; void strReverse(char *original) { char temp; int i; int j; for (i = 0,...

request for comments on original crc32 checksum

Can someone explain to me why the crc is inverted twice ? /* ======================================================================== * Table of CRC-32's of all single-byte values (made by make_crc_table) */// definicao de uint e uchar #include <stdio.h> //#define TEST 1 #ifndef uchar #define uchar unsigned char #endif #ifndef ui...

How to check if port is available

Is there an API function on Linux (kernel 2.6.20) which can be used to check if a given TCP/IP port is used - bound and/or connected ? Is bind() the only solution (binding to the given port using a socket with the SO_REUSEADDR option, and then closing it) ? ...

How to change underlining color in a Rich Edit control (Win32/C)

I’m looking for a way to make red squiggly underlining in a Rich Edit control (I’m using version 4.1 with Msftedit.dll). I’m able to produce squiggly underlining with this code : CHARFORMAT2 format; format.cbSize = sizeof(format); format.dwMask = CFM_UNDERLINETYPE; format.bUnderlineType = CFU_UNDERLINEWAVE; SendMessage(hWndEdit,EM_SETCH...

Stack Size Estimation

In multi-threaded embedded software (written in C or C++), a thread must be given enough stack space in order to allow it to complete its operations without overflowing. Correct sizing of the stack is critical in some real-time embedded environments, because (at least in some systems I've worked with), the operating system will NOT dete...

Determine Stack bottom, start and end of data segment of C program

Hi, I am trying to understand how memory space is allocated for a C program. For that , I want to determine stack and data segment boundaries. Is there any library call or system call which does this job ? I found that stack bottom can be determined by reading /proc/self/stat. However, I could not find how to do it. Please help. :) ...

Does GCC's __attribute__((__packed__))...?

Purpose I am writing a network program in C (specifically gnu89) and I would like to simplify things by reinterpreting a certain struct X as big array of bytes (a.k.a. char), sending the bytes over the network, and reinterpreting them as struct X on the other side. To this end I have decided to use gcc's __attribute__((__packed__ )). I ...

CPU cache flush

I am interested in forcing a CPU cache flush in Windows (for benchmarking reasons, I want to emulate starting with no data in cpu cache), preferably a basic C implementation or win32 call. Is there a known way to do this with a system call or even something as sneaky as doing say a large memcopy? Intel i686 platform (P4 and up is okay as...

Compiling an ANTLR 3 grammar in C.

I've been trying to learn ANTLR and get it working with C output code using this tutorial (also referenced in this question). I successfully got ANTLR to generate the lexer and parser as C source, but I cannot get them to compile using gcc on Mac OS X Snow Leopard (i686-apple-darwin10-gcc-4.2.1). Below is the result when I try to compile...

Which unit testing framework to use for C development on Windows?

On Windows XP, using TDM's GCC/MinGW32 for basic development i.e. gcc 4.4.x with gdb. Which unit testing framework to use for test driven development? Apparently Check's unit tests don't yet work on Windows. The questions at Unit Testing Frameworks for C and Unit Testing C Code are similar but not specifically about using gcc 4.4.x on ...

Is there any software which could make architecture diagram out of existing source code?

Imagine you have a huge peace of C spaghetti-code covering most of existing anti-patterns. You need to realise what calls exactly what quickly. And you cannot build it - only very few people can do it. Is there any software which could make architecture diagram out of existing source code? ...

How to tell Windows Explorer to refresh its icons?

Once my installer finishes installing new versions of my application's exe, I'd like to tell Explorer to use the new exe's icons for its shortcuts. However, I cannot figure out how to do this. From reading online, it looks like the problem is that the system image list is caching an old version of the icon. I tried calling SHChangeNot...

How come replacing char[] with IntPtr or StringBuilder in a DllImport return value causes my program to no longer find the correct entry point?

EDIT: I just realized this is defined as a MACRO, not a function. How the heck would I import a macro from a DLL to C#? (this may have to be a new question). This is related to a question I just asked: How Do I Properly Return A Char From An Unmanaged Dll To C#? Some of the answers suggested I change the function signature to Int...

Alarm history stack or queue?

I'm trying to develop an alarm history structure to be stored in non-volatile flash memory. Flash memory has a limited number of write cycles so I need a way to add records to the structure without rewriting all of the flash pages in the structure each time or writing out updated pointers to the head/tail of the queue. Additionally once...

What are function pointers used for, and how would I use them?

I understand I can use pointers for functions. Can someone explain why one would use them, and how? Short example code would be very helpful to me. ...

How do I have a variable in C that can accept various types?

Hi, I'm looking to implement a dictionary data structure in C which I want to be as generic as possible. That is to say it can accept a pair of values that can be of any type. How can I init a variable that can accept any types? And how can I convert that type back to a type I want? (Typecast) Thanks. ...

How to check if structs are initialised or not

typedef struct dict_pair { void *key; void *value; struct dict_pair *head; struct dict_pair *tail; } dict; dict* NewDictionary(void) { dict *dictionary = malloc(sizeof(dict_pair)); dictionary->head = null; dictionary->tail = null; } int main(void) { dict *dictionary = NewDictionary(); } I had initially planned to set ...

Pthreads question

How to check if a thread is terminated? In my case, I have my_pthread[5] and I want to check if any in 5 threads has finished its job (terminated???I'm not sure) then I can give them another work to do. If I use pthread_join(), then it has to be pthread_join(my_pthread[0]); ... pthread_join(my_pthread[4]); What if thread[3] finishes...

the quake 2 md2 file format (theory)

i am trying to load md2 files in opengl but i noticed that most example programs just use a precompiled list of normals. something like this..... //table of precalculated normals { -0.525731f, 0.000000f, 0.850651f }, { -0.442863f, 0.238856f, 0.864188f }, { -0.295242f, 0.000000f, 0.955423f }, { -0.309017f, 0.500000f, 0.80901...

Need help understanding pointers and various other C stuff

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct dict_pair { void *key; void *value; struct dict_pair *tail; } dict; dict* NewDictionary(void) { dict *dictionary = malloc(sizeof(dict)); //or we can malloc(sizeof(struct dict_pair)) dictionary->tail = NULL; } //dict operations void put(dict *dictionar...