Is it a good idea for C API functions to allocate their output, or to have the user specify the output buffer? For example:
BOOL GetString(
PWSTR *String
);
...
PWSTR string;
GetString(&string);
Free(string);
vs
BOOL GetString(
PWSTR Buffer,
ULONG BufferSize,
PULONG RequiredBufferSize
);
...
// A lot more code...
I understand Linux ships with a c library, which implements the ISO C functions and system call functions, and that this library is there to be linked against when developing C. However, different c compilers do not necessarily produce linkable code (e.g. one might pad datastructures used in function arguments differently from another). ...
Any good alternative written in C to replace Boost.Program_options? Given it's able to parse:
Short options like -h
Long options like --help --input-file
Parse repeated keys/options
Accepts key-value pairs: --mysql=/usr/lib
Parsing environmental variables and XML/INI files is optional.
...
I have two tasks for an assignment, one return the number of bits in type int on any machine. I thought I would write my function like so:
int CountIntBitsF() {
int x = sizeof(int) / 8;
return x;
}
Does that look right?
The second part is to return the number of any bits of any data type with a macro, and the macro can be ...
I am trying separate a CUDA program into two separate .cu files in effort to edge closer to writing a real app in C++. I have a simple little program that:
Allocates a memory on the host and the device.
Initializes the host array to a series of numbers.
Copies the host array to a device array
Finds the square of all the elements in the...
~ Please forgive me -
I had a previous post called IEEE - 754 - find signbit, exponent, frac, normalized, etc..
However, i had not registered my nic and i cant edit it. ( so the post is basically dead to me) Can someone delete it? My question is unanswered also.
So i am posting this with different code.
i still need lots of help...
Normal file related functions like fseek, ftell etc in Windows MSVC6 can handle files only upto 2GB (As per my current understanding, Please correct me if I am wrong).
I want to work with files >2GB. How should I go about it? What are the functions available?
...
I need to save very large amounts of data (>500GB) which is being streamed (800Mb/s) from another device connected to my PC. The speed rules out use of a database e.g. MySQl/ISAM and I am looking for a fast, light library which sits on top of the 'C' stdio file lib (i.e. fopen/fclose/fwrite) which will allow me to write/read a very larg...
Hi,
I have seen a strange behavior with "strndup" call on AIX 5.3 and 6.1.
If I call strndup with size more than the size of actual source string length, then there is a stack corruption after that call.
Following is the sample code where this issue can come:
int main ()
{
char *dst_str = NULL;
char src_str[1023] = "sample st...
In C/C++ why globals and static variables are initialized to default values.. why not leave it with just garbage values ? Any special reasons for this ?
...
so I want to copy a char pointer, asked a friend and he said to use memcpy... so I am trying to do this:
charFilenameAndPath=strtok(filename,".");
memcpy=(charFilename,charFilenameAndPath, sizeof(charFilenameAndPath));
and the compiler is spitting out this:
uTrackSpheres.cpp:176: error: assignment of function ‘void* memcpy(void*, co...
In C, arrays are passed to functions as pointers. Structures can be passed to functions either by value or by address (pointer). Is there any specific reason why we can not pass array by value but we can pass structre by value ?
...
I want to execute a command using system() command or execl and want to capture the output directly in a buffer in C. Is ther any possibility to capture the output in a buffer using dup() system call or using pipe(). I dont want to use any file in between using mkstemp or any other temporary file. please help me in this.Thanks in advance...
I have a bug where a char pointer is turning out NULL. I've been all over gdb with the program, watching read/write at the memory address, and stepping through the instructions, but so far the bug stumps me. I've ran valgrind and the only thing coming up is the read at the crash (strcmp). What else can I do to track this down?
...
How to make a native API to be PInvoke friendly?
there are some tips on how to modify native-programs to be used with P/Invoke here. But before I even write a native programs, what are the things I should look out to make my programs/library PInvoke friendly?
using C or C++ are fine.
update:
if I write a C API, what are the things I h...
Hi
How can i split a string into tokens by '&' ?
...
Hi, I am really new to C.
I want to use the strpos function but it is telling me it doesnt exist?
...
I want to send a file in C++ over network (for a chat program)
what should I do?
...
I've got a problem where I have to read from a named pipe. I have to handle the situation where writers to the named pipe come and go but I need to keep the same pipe open throughout my applications.
I have summarised this in the following code.
int main( int c, char *v[] )
{
int rfd;
if ( (rfd = open( PIPENAME, O_RDONLY | O_NO...
Hi All, i have written the following code to copy a string "hello world" to another char array using fork and pipes instead of using standard library functions or standard i/o streams. The program is compiling successfully but i am not getting any output. Even, the printf's output are not being shown.
# include <string.h>
# include <uni...