In C or C++, there is no checking of arrays for out of bounds. One way to work around this is to package it with a struct:
struct array_of_foo{
int length;
foo *arr; //array with variable length.
};
Then, it can be initialized:
array_of_foo *ar(int length){
array_of_foo *out = (array_of_foo*) malloc(sizeof(array_of_foo));
out...
Hello,
I would like to know whether it is possible to call a CreateFile Function in Visual C++ to create a file with attribute FILE_ATTRIBUTE_DEVICE (0x00000040 hex, 64 decimal). According to the MSDN API, FILE_ATTRIBUTE_DEVICE is reserved and therefore I cannot use it, but I know there must be some way to create a file with such attrib...
How variable beyond "unsigned long long" size is represented in C or any programming language. Is there are variable type to represent Infinity?
...
I have a dll which is dependent of OPENGL.DLL . However, Windows comes with OpenGL32.dll . I want to change this dependency name in the dll binary so it looks for OpenGL32.dll instead. I tried opening it in VS's binary editor but I cant seem to make the name longer. I can for instance change it to OpenDD.dll but I cant add to it. How cou...
Is there a dev kit/lib (written in c or c++) to write docx files? Microsoft has a dev kit, but it's written in C#.
...
Hello,
which is the beast approach to send packets that can be of different size using TCP sockets in C?
I wonder because we're trying to write a multiplayer games that needs a protocol which has many kinds of packets of different sizes.. according to recv documentation I can get how many bytes have been read but how should I manage to ...
Hi,
I'm trying to do some kind of Macro "Overloading", so that MACRO(something), gets expanded differently than MACRO(something, else).
Using a snippet I got from here (I'm not sure if it's 100% portable) and some functions from the Boost PP Library, I was able to make it work :D
//THESE TWO COUNT THE NUMBER OF ARGUMENTS
#define VA_NA...
Hi folks, let me first off noting that I have absolutely no idea what I'm doing with objective-c and mac development (though I'm fine with c). I made a wonderfully simple graphics utility on leopard with the Quartz-2d binding for python:
http://developer.apple.com/graphicsimaging/pythonandquartz.html
that basically inputs a text file ...
Hello,
gcc 4.4.4 c89
What is better to convert a string to an integer value.
I have tried 2 different methods atoi and sscanf. Both work as expected.
char digits[3] = "34";
int device_num = 0;
if(sscanf(digits, "%d", &device_num) == EOF) {
fprintf(stderr, "WARNING: Incorrect value for device\n");
return FALSE;
}
or using a...
I have a huge data in excel sheet. I need to prepare a structure for that data and fill the data. I can do it in 2 ways.
statically fill the structure during struct initialization
struct x a[] = { }
Dynamically fill the structure by allocating memory and filling it in a function.
My structure also looks little complicated. How do I f...
I have a list of n strings (names of people) that I want to store in a hash table or similar structure. I know the exact value of n, so I want to use that fact to have O(1) lookups, which would be rendered impossible if I had to use a linked list to store my hash nodes. My first reaction was to use the the djb hash, which essentially d...
The question basically is similar to what is posted here http://stackoverflow.com/questions/1514382/example-of-a-while-loop-that-cant-be-a-for-loop except that there isn't one such example where a certain program using the while loop cannot be replaced by the for loop because of its limitations.
An example is
i=0;
while(i<10)
{
continu...
#undef GOOGLE_LONGLONG
#undef GOOGLE_ULONGLONG
#undef GOOGLE_LL_FORMAT
#ifdef _MSC_VER
#define GOOGLE_LONGLONG(x) x##I64
#define GOOGLE_ULONGLONG(x) x##UI64
#define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...)
#else
#define GOOGLE_LONGLONG(x) x##LL
#define GOOGLE_ULONGLONG(x) x##ULL
#define GOOGLE_LL_FORMAT "ll" // As in "%lld...
I am wondering how I can effectively find the usages of a function/structure in the files using find & grep combination.
For example, I have source code for git on my machine. If you look at the commit.h, you can see commit structure is defined like,
struct commit {
struct object object;
void *util;
unsigned int indegree;
...
Hi there,
This is the first time that I use the JNI and also the first time that I have to write some lines in C.
What I am trying to do is very simple. I'm just trying to switch the endiannes of a byte[] using a C routine.
In java it is done like this:
public void switchEndianness(byte[] array){
byte byte1;
byte by...
Hi there, I'm stuck with a weird problem.
I have two files a.c and b.c as follows:
b.c:
#include <stdlib.h>
int *foo() {
int *x;
x = (int *) malloc(sizeof(int));
*x = 4;
return x;
}
I compile b.c to b.so using gcc:
$ gcc -o b.so -shared -fpic
a.c:
#include <stdio.h>
#include <dlfcn.h>
int main() {
void *hdl;
hdl = dlop...
I have to work with two C programs that communicate via a file-based interface. That is, each of them has a main loop where it polls three or four files (fopen, fscanf), reacts to what it reads and eventually makes its own changes to the files (fprintf) for the other process to read.
Now I have to condense these two programs into a sing...
Suppose I want to share a global array of data across my program, for example:
int lookup_indexes[] = { -1, 1, 1, -1, 2, 1, 1, -2, 2, 2, -1, 1, 1, 2 };
What is the correct extern declaration for this array in the C header file?
Also what about an array like this:
int double_indexes[][5] = { { -1, 1, 1, -1, 1 }, { 2, -2, 2, 1, -1 } }...
I usually use C type casting in C/C++ code. My question is, does adding the "const" keyword in the casting type mean anything to the result?
For example, I can think up several scenarios:
const my_struct *func1()
{
my_struct *my_ptr = new my_struct;
// modify member variables
return (const my_struct *)my_ptr;
// return my...
I have a requirement to (very) quickly process strings of a limited range, tallying their values. The input file is of the form:
January 7
March 22
September 87
March 36
and so forth. Because the line widths are identical, I can simply read in a line with fread reasonably fast, and I've developed a perfect hashing function ...