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

Re: random_r functies



Eric Meijer schreef:

> ---- testrand.c ----
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char* argv[])
> {
>  struct random_data state1;
>  const size_t bufsz = 256;
>  char buf1[bufsz];
>  int32_t r1;
>
>  fprintf(stderr, "%d\n", initstate_r(1u, buf1, bufsz, &state1));
>  random_r(&state1, &r1);
>  fprintf(stderr, "%d\n", r1);
>
>  return 0;
> }
> ----
>
> Als ik dit bouw met gcc 4.4.5 op een up-to-date squeeze systeem met
> gcc -o testrand testrand.c
> dan krijg ik een executable die een segmentation fault geeft in de file
> "random_r.c" die niet op het systeem staat
> (volgens gdb).

Sorry, maar ik krijg niet eens een executable. Ik heb jouw
programmaatje testrand.c gecompileerd op een volledig up-to-date
Cygwin systeem. Voor de volledigheid heb ik de optie -Wall toegevoegd.

$ gcc --version
gcc (GCC) 4.5.3

$ gcc -Wall -o testrand testrand.c
testrand.c: In function 'main':
testrand.c:6:21: error: storage size of 'state1' isn't known
testrand.c:11:2: warning: implicit declaration of function 'initstate_r'
testrand.c:12:2: warning: implicit declaration of function 'random_r'
testrand.c:6:21: warning: unused variable 'state1'

Compileren met g++ in plaats van gcc geeft ook fouten:
$ g++ -Wall -o testrand testrand.c
testrand.c: In function 'int main(int, char**)':
testrand.c:6:21: error: aggregate 'main(int, char**)::random_data
state1' has incomplete type and cannot be defined
testrand.c:11:62: error: 'initstate_r' was not declared in this scope
testrand.c:12:23: error: 'random_r' was not declared in this scope

Hernoemen van testrand.c naar testrand.cpp en compileren met g++
levert dezelfde meldingen.

Vriendelijke groeten,
Arjen Bax




>
> Heeft iemand enig idee of ik hier nog iets fout doe?  Zijn er debian mailing
> lists die voor dit soort vragen geschikter zijn?
> Ik draai kernel 2.6.32-5-686-bigmen, libc6-dev 2.11.2-10.
>
> Groeten,
> Eric
>
>
> --
> To UNSUBSCRIBE, email to debian-user-dutch-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact
> listmaster@lists.debian.org
>
>


Reply to: