I have a function in unmanaged C/C++ code (dll) that returns a structure containing a char array. I created C# struct to receive this return value uppon calling the function. And uppon calling this function i get 'System.Runtime.InteropServices.MarshalDirectiveException'
This is C declaration:
typedef struct T_SAMPLE_STRUCT {
int num;
...
I'd like to declare a function that returns a pointer to a function of the same type.
I would like to use it to implement state machines like the one below:
typedef event_handler_t (*event_handler_t)(event_t*); // compilation error
event_handler_t state2(event_t* e);
event_handler_t state1(event_t* e) {
switch(e->type) {
//...
cas...
I'm trying to think of a clever way (in C) to create an array of strings, along with symbolic names (enum or #define) for the array indices, in one construct for easy maintenance. Something like:
const char *strings[] = {
M(STR_YES, "yes"),
M(STR_NO, "no"),
M(STR_MAYBE, "maybe")
};
where the result would be equivalent to:
...
Just want to document the answer to this specific question... a similar question (with potential answers was asked here)
All platforms welcome, please specify the platform for your answer.
...
The compiler doesn't know where stat.h is?
Error:
c:\Projects\ADC_HCI\mongoose.c(745) : error C2079: 'st' uses undefined struct '_stat64'
#include <sys/types.h>
#include <sys/stat.h>
static int
mg_stat(const char *path, struct mgstat *stp)
{
struct _stat64 st; //<-- ERROR
int ok;
wchar_t wbuf[FILENAME_MAX];
to_uni...
I would like to use some previously defined constants in the definition of a new constant, but my C compiler doesn't like it:
const int a = 1;
const int b = 2;
const int c = a; // error: initializer element is not constant
const int sum = (a + b); // error: initializer element is not constant
Is there a way to define a constan...
I'm learning C and I'm reading about type equivalence.
I'm curious, does anyone have an opinion why they used structural equivalence for arrays and pointers but they used declaration equivalence for structs and unions?
Why the disparity there? What is the benefit of doing declaration equivalence with structs/unions and structural equi...
Sorry if this is a noob question :( .
Piece of C code.
int array[5];
int cnt;
for(cnt = 0; cnt <= 10; cnt+=1)
{
array[cnt] = cnt;
}
Should give an error, right? No! Works fine!
But why is that? It seems that -in the first line- an array of more than the double size (11) is defined. You can even access array[5 to 10] later on....
I'm working on a project where I need to find which functions get called in various Linux programs (written in C) given particular inputs. My current approach has been to compile a program with -pg (profiling option), run it, and find which functions get called by processing gprof's output. Only functions that are called at least once ap...
What are some cross platform and high performance image libraries for image processing (resizing and finding the color/hue histograms). No gui needed. This is for C/C++.
So far I have looked in to
OpenCV
GIL as part of Boost
DevIL
CImg
My questions
How's the performance of the ones I have listed above
What are some other librari...
Hello,
Are there any known false positives with Valgrind?
(myself I get a 'Conditional jump or move depends on uninitialised value(s)' with the 'fmemopen' function, writing in 'c' and gcc, can I be sure it's real?)
EDIT: are there known issues that are not in the suppression files?
Are there some things one can do in a program, that ...
Hello,
I am currently writing a systems programming homework and in one part i need to get some information of a file in a directory.
for the stat of file, we have ctime() function which converts time_t type to string and returns a pointer to it.
but how about the uid_t and off_t types? I searched through to internet and couldnt find ...
I have a pretty long sqlite query:
const char *sql_query = "SELECT statuses.word_id FROM lang1_words, statuses WHERE statuses.word_id = lang1_words.word_id ORDER BY lang1_words.word ASC";
How can I break it in a number of lines to make it easier to read?
If I do the following:
const char *sql_query = "SELECT word_id
...
Hi guys,
i wanna write Driver for my network adapter .For the suggest any e books or online tutorial for Driver development?
...
I am trying to port a tool to osx which is designed to run on linux and freebsd. There is a case in the program where access to the EIP and EBP is need. This is done via the ucontext.
So i added a case for __APPLE__ to place a suitable access to the ucontext struct.
9887 #if defined(__FreeBSD__)
9888 *paddr = uc->uc_mcontext....
I would like to use C #define to build literal strings at compile time.
The string are domains that change for debug, release etc.
I would like to some some thing like this:
#ifdef __TESTING
#define IV_DOMAIN domain.org //in house testing
#elif __LIVE_TESTING
#define IV_DOMAIN test.domain.com //live testing servers
#else
...
Hi,
I'm interested in the configuration/building of large C systems...
The Linux kernel uses the Kconfig language to describe the various configuration options (macros defined as CONFIG_X) and their dependencies... Basically, in each directory, there's a Kconfig file with the configuration options defined in this subsystem...
Is there...
I had a colleague check in code like this in C (syntax #1):
(*(*(*p_member).p_member).p_member).member
When I asked him why he didn't use -> (syntax #2):
p_member->p_member->p_member->member
he got really defensive stating that syntax #2 is more complicated than #1...I ended up changing his code because I had to modify it and cou...
I'm looking at some open source projects and I'm seeing the following:
NSLog(@"%s w=%f, h=%f", #size, size.width, size.height)
What exactly is the meaning of '#' right before the size symbol? Is that some kind of prefix for C strings?
...
Hi,
i have some bidimensional arrays like:
int shape1[3][5] = {1,0,0,
1,0,0,
1,0,0,
1,0,0,
1,0,0};
int shape2[3][5] = {0,0,0,
0,0,0,
0,1,1,
1,1,0,
0,1,0};
and so on.
How can i make an array of pointers to those?
I tried the following, but they don't work (warning: initializat...