c

size_t vs int in C++ and/or C

Why is it that in C++ containers, it returns a size_type rather than an int? If we're creating our own structures, should we also be encouraged to use size_type? ...

How can I parse a C header file with Perl?

Hi, I have a header file in which there is a large struct. I need to read this structure using some program and make some operations on each member of the structure and write them back. For example I have some structure like const BYTE Some_Idx[] = { 4,7,10,15,17,19,24,29, 31,32,35,45,49,51,52,54, 55,58,60,64,65,66,67,69, 70,72,76,7...

Is there ever a need for a "do {...} while ( )" loop?

Bjarne Stroustrup (C++ creator) once said that he avoids "do/while" loops, and prefers to write the code in terms of a "while" loop instead. [See quote below.] Since hearing this, I have found this to be true. What are your thoughts? Is there an example where a "do/while" is much cleaner and easier to understand than if you used a "wh...

Allocate data through a function (ANSI C)

Hi all, I d love to know how I can allocate data through a function, and after the function is returned the data is still allocated. This is both for basic types (int, char**) and user defined types. Below are two snipsets of code. Both have the allocation within the function though after the return the allocation goes. int* nCheck = N...

Question about pointer in C?

int a[A][B]; int* p = a[i]; //i<A-1 then what's the actual operation of the sentence below? p++; p+=B; ...

Best strategy to call an arbitrary function without using JMP or LCALL

In embedded C is quite natural to have some fixed/generic algorithm but more than one possible implementation. This is due to several product presentations, sometimes options, other times its just part of product roadmap strategies, such as optional RAM, different IP-set MCU, uprated frequency, etc. In most of my projects I deal with th...

Building a lexer in C

I want to build a lexer in C and I am following the dragon book, I can understand the state transitions but how to implement them? Is there a better book? The fact that I have to parse a string through a number of states so that I can tell whether the string is acceptable or not! ...

Where can I find C coding exercises to practice?

Tutorials are a dime a dozen, but I'd like to find a list of exercises online that I could attempt to practice what I'm learning. The sort of things that start with "Write a program to..." I'm an absolute beginner, so basic exercises increasing in difficulty would be great. ...

Pass Pointer to an Array in Haskell to a C Function

I have the following C code: #include <sys/times.h> #include <time.h> float etime_( float *tarray ) { struct tms buf; times( &buf ); tarray[0] = 1.0 * buf.tms_utime / CLOCKS_PER_SEC; tarray[1] = 1.0 * buf.tms_stime / CLOCKS_PER_SEC; return tarray[0] + tarray[1]; } Trying to port this Fortran code to Haskell: ...

Comparison of static code analysis tools in Linux?

Has anyone done any comparisons on static code analysis tools available to Linux? What are the strengths and weaknesses of the following tools: Lintian, Sparse, Splint, RATS, Using the -Wall option. Would you consider that using just one of these tools is adequate? I'm not looking for recommendations (I can find plenty of those) b...

big int compiler implementations?

i am building a compiler similar to c , but i want it to parse integers bigger than 2^32 . hows it possible?how has been big integers been implemented in python and ruby like languages ..!! ...

modifying a function parameter (a pointer) from within the application

This is a question based on C code for Win32. In one of my functions I have the following code: void SeparateStuff() { HGLOBAL hMem; IStream* pStream; Status result; unsigned char* pBytes; DWORD size; FILE* fp; if (hMem = GlobalAlloc(GMEM_MOVEABLE, 0)) { if (CreateStreamOnHGlobal(hMem, FALSE, &pStr...

Regex for refactoring to arrays

I have a very big C programming project that uses thousands of struct variables with this naming convention: specificstruct->x = specificstruct->y + specificstruct->z I want to do some heavy refactoring, namely converting most of these struct members to arrays. The code above would look like this: specificstruct->x[i] = specificstruct...

Content for Linux Operating Systems Class

I will be TA for an operating systems class this upcoming semester. The labs will be deal specifically with the Linux Kernel. What concepts/components of the Linux kernel do you think are the most important to cover in the class? What do you wish was covered in your studies that was left out? Any suggestions regarding the Linux kerne...

How can I take a screenshot and save it as JPEG on Windows?

I'm trying to find a (somewhat) easy way to take a screenshot on window and save the resulting HBITMAP as a JPEG. The tricky part here is that since the code is in C I can't use GDI+ and since the code is a module for a bigger program I can't neither use an external lib (like libjpeg). This code takes a screenshot and returns a HBITMAP....

Poker code cleanup modification from book...not quite right...

Working through more book examples- this one is a partial poker program- This segment deals with straight hand.... First what was given- only relevant parts....will provide entire code if needed... int suits[5]; //index 1..4- value start at 1 int values[14]; //index 1..13- value same as rank, A = 1, K = 13 cin.get(rankCh); switch (toU...

How to compile using VS2008 so binary doesn't require .NET?

I'm trying to compile a very simple C application using VS2008. My problem is that the resultant binary requires systems to have .NET installed. No actual code within the project uses .NET functionality, but I get errors during execution on any system that doesn't have .NET. So, is there anyway to compile using VS2008 so the resultant ...

Haskell FFI: Calling FunPtrs

Here's my situation: I would like to call ffmpeg's av_free_packet function: // avformat.h static inline void av_free_packet(AVPacket *pkt) { if (pkt && pkt->destruct) pkt->destruct(pkt); } But unfortunately this function is static inline, and so doesn't really appear in the linked library. However, it is a very simple function...

Problems with a Linked List in C

I'm making a linked list (of structs) in C, but I want to be able to call a function and have it add 4-5 stucts to the list by itself. The problem is since in C all the variables created in functions are left on the stack/heap I have no clue how I am supposed to accomplish this. Here is a code example: struct listItem { int value; ...

OpenCV: Accessing And Taking The Square Root Of Pixels

I'm using OpenCV for object detection and one of the operations I would like to be able to perform is a per-pixel square root. I imagine the loop would be something like: IplImage* img_; ... for (int y = 0; y < img_->height; y++) { for(int x = 0; x < img_->width; x++) { // Take pixel square root here } } My question is how can...