Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 10-09-2003, 11:38 PM   #1
darkone
Disabled
FlashFXP Registered User
ioFTPD Administrator
 
darkone's Avatar
 
Join Date: Dec 2001
Posts: 2,230
Default [c] Building va_list on heap

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>

typedef struct _my_valist
{
unsigned int length;
unsigned int size;
void *data;
void *ptr;

} my_valist;



#define va_add(v, x, t) \
((sizeof(t) <= v.size - v.length) && memcpy((void *)((long)v.data + v.length), &x, sizeof(t)) && (v.length += sizeof(t)) || \
((v.ptr == realloc(v.data, v.size * 2)) && (v.size *= 2) && (v.data = v.ptr) && memcpy((void *)((long)v.data + v.length), &x, sizeof(t))) && (v.length += sizeof(t)))




int main(int argc, char *argv[])
{
int dummy;
my_valist ap;
va_list app;
int myint;
char *mystr = "hello";


ap.data = (char *)malloc(1024);
ap.size = 1024;
ap.length = 0;

if (va_add(ap, mystr, char *)) printf("ok\n");
if (va_add(ap, ap.length, char *)) printf("ok\n");

app = ap.data;
mystr = va_arg(app, char *);
myint = va_arg(app, long);

printf("%s %i\n", mystr, myint);

exit(0);
}
darkone is offline  
Closed Thread

Tags
int, unsigned, void

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:41 PM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)