[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: asprintf



> X-Authentication-Warning: malle.axis.se: majordom set sender to owner-dev-etrax@xxxxxxx.se using -f
> From: Hansen Martin <DKDD0MAR@xxxxxxx.com>
> Date: Tue, 30 Apr 2002 11:31:26 +0200

> But the I discovered asprintf that automatically allocates space for a
> string, so now I could:
> 
> char* s;
> sprintf(&s,"qwerty")
> 
> But I cant compile this GNU function with cris ;o((
> Any suggestions?

More details, please.  A complete program and the reason you
think you can't compile it with gcc-cris (supposedly compiler
error messages).  Comparing behavior with the host gcc would
also help.

The program below (xy.c) compiles and links for me compiling
with "gcc-cris -W -Wall -mlinux -c xy.c -o xy" but since
asprintf isn't an ISO-function (it's a BSD thingy), it's not
declared by default in stdio.h; you need to add -D_GNU_SOURCE to
the flags above for that.

#include <stdio.h>
#include <stdlib.h>
size_t guesize(void) { return 1;}
int main (void)
{
  char* s;
  size_t size;
  size=guesize();
  malloc(size);
  asprintf(&s,"qwerty");
  exit (0);
}

brgds, H-P