c - <cstdio> issues: Filename extension for tmpnam(), rand() generation algorithm advance, & fgetc()'s stream expression -
i had finished reading stdio.h functions , need small clarifications.
please take minute give short explanations following:
1) tmpnam() : gives string containing unique file-name, file extensions?will have use strcat() each time add file extension file name?
2) rand() : following mean in context of rand() (taken cplusplusreference)?:
"in c, generation algorithm used rand guaranteed advanced calls function"
i checked it, repeatedly calling rand() 1 after same seed, doesn't give increasing values!
3) getc() : part in bold mean in following description of parameter of getc() taken same site(getc())?
"---parameter
pointer file object identifies input stream.
because libraries may implement function macro, , may evaluate stream expression more once, should expression without side effects."
- you can't modify filename returned unless supplied buffer , know how big is. string copying or modifying function work.
- it means sequence of numbers returned
rand()affected callsrand()function itself: no matter in between callsrand(), you'll same outputs. is, underlying function advanced callsrand(). doesn't mean output increasing. it means
getc()may macro evaluates argument twice. why don't try , work out possible outcomes code might have:int = 0; (void)getc((++i,stdin)); printf("%d\n", i);here's example of implementation uses macro
getc(): aix docs. if remember correctly, you'll trouble on aix if don't pass right pointerfileno,dirfd, , others too. looks opensolaris definition, though don't have copy hand (glibc, freebsd, don't use macro).#define getc(p) (--(p)->_cnt>=0? ((int)*(p)->_ptr++):_filbuf(p))
Comments
Post a Comment