Hi,
I have trouble seing the utility of the function pointers. I guess it may be useful in some cases (they exist, after all), but I can't think of a case where it's better or unavoidable to use a function pointer.
Could you give some example of good use of function pointers (in C or C++)?
Many thanks :)
...
I'm currently working on an embedded linux system. There are two crucial client applications on the system that connect to an external server ( on another embedded system, all written in C ). The two apps use different certificates.
The ssl connection works... At least usually, but from time to time an error occures: the server hangs on...
Let's say i have 15 processes/daemons running in the background.
let's say one of the process has dumped the core.
how could i identify which process has dumped the core.
i am using hpux!
...
I ran across the following code in one of our in-house dlls and I am trying to understand the behavior it was showing:
long GetFD(long* fd, const char* fileName, const char* mode)
{
string fileMode;
if (strlen(mode) == 0 || tolower(mode[0]) == 'w' || tolower(mode[0]) == 'o')
fileMode = string("w");
else if (tolowe...
I have a macro definition in header file like this:
// header.h
ARRAY_SZ(a) = ((int) sizeof(a)/sizeof(a[0]));
This is defined in some header file, which includes some more header files.
Now, i need to use this macro in some source file that has no other reason to include header.h or any other header files included in header.h, so sho...
Hello,
I'm trying to use SCons for building a piece of software that depends on a library that is available in sources that are installed in system. For example in /usr/share/somewhere/src. *.cpp in that directory should be built into static library and linked with my own code. Library sources have no SConscript among them.
Since libra...
Can someone help me find the errors in this C function?
char* f(int i) {
int i;
char buffer[20];
switch ( i ) {
1: strcpy( buffer, "string1");
2: strcpy( buffer, "string2");
3: strcpy( buffer, "string3");
default:
...
These days I'm working on a VB.NET application which can be used to edit, compile and run C programs. Can someone tell me how I can call a cl.exe process from within my VB program and also that how do I run the program in the console widow itself.
Presently I have only the editor ready. With that one can type in a program and save it wi...
Does anyone know of a tool that I can use to find explicit C-style casts in code? I am refactoring some C++ code and want to replace C-style casts where ever possible.
An example C-style cast would be:
Foo foo = (Foo) bar;
In contrast examples of C++ style casts would be:
Foo foo = static_cast<Foo>(bar);
Foo foo = reinterpret_cast<...
Suppose, I have a connected socket after writing this code..
if ((sd = accept(socket_d, (struct sockaddr *)&client_addr, &alen)) < 0)
{
perror("accept failed\n");
exit(1);
}
How can I know at the server side that client has exited.
My whole program actually does the following..
Accepts a connection from client
Starts a new ...
Hi there,
I am getting segmentation fault when using strncpy and (pointer-to-struct)->(member) notation:
I have simplified my code. I initialise a struct and set all of it's tokens to an empty string. Then a declare a pointer to a struct and assign the address of the struct to it.
I pass the pointer to a function. I can print out the ...
Hello,
I find such examples in Boost code.
namespace boost {
namespace {
extern "C" void *thread_proxy(void *f)
{
....
}
} // anonymous
void thread::thread_start(...)
{
...
pthread_create(something,0,&thread_proxy,something_else);
...
}
} // boost
Why do you actually need thi...
Hi,
I don't understand why atoi() is working for every entry but the first one. I have the following code to parse a simple .csv file:
void ioReadSampleDataUsers(SocialNetwork *social, char *file) {
FILE *fp = fopen(file, "r");
if(!fp) {
perror("fopen");
exit(EXIT_FAILURE);
}
char line[BUFSIZ], *word, ...
I'm writing a client application to communicate with a server program via UDP. The client periodically makes requests for data and needs to use the most recent server response. The request message has a 16-bit unsigned counter field that is echoed by the server so I can pair requests with server responses.
Since it's UDP, I have to ha...
I'm working with libpcap in C on linux (centos) and I'm following this guide I want to simply print out the entire packet in ascii and i'v managed to get it working by casting it a u_char* in the "my_callback" function. But I can't figure out how to get the length of the data. strstr didn't work. the header has a len member that you can ...
Hi I have an enum declared like this:
typedef enum {
Top,
Bottom,
Center
} UIItemAlignment;
In my code I try to use it like this:
item.alignment = UIItemAlignment.Top;
I get an error like this: " Expected expression before 'UIItemAlignment' "
If I use only:
item.alignment = Top;
everything works fine bu...
Hi,
I'm developing for a platform without a math library, so I need to build my own tools. My current way of getting the fraction is to convert the float to fixed point (multiply with (float)0xFFFF, cast to int), get only the lower part (mask with 0xFFFF) and convert it back to a float again.
However, the imprecision is killing me. I'm...
Hi, with MVS2008, this line works fine:
_fsopen(file_name, "wb+", _SH_DENYRW);
Borland C++builderX from 2003 complains about the argument _SH_DENYRW. I changed to
_fsopen(file_name, "wb+", SH_DENYRW);
removing the underscore and Borland compiles well now. Is it good what I'm doing? I saw this modification somewhere on the web.
T...
I have a rather long switch-case statement. Some of the cases are really short and trivial. A few are longer and need some variables that are never used anywhere else, like this:
switch (action) {
case kSimpleAction:
// Do something simple
break;
case kComplexAction: {
int specialVariable = 5;
// ...
I cant find an expression to evaluate a part of a string.
I want to get something like that:
if (string[4:8]=='abc') {...}
I started writing like this:
if (string[4]=='a' && string[5]=='b' && string[6]=='c') {...}
but if i need to evaluate a big part of string like
if (string[10:40] == another_string) {...}
then it gets to wri...