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."

  1. you can't modify filename returned unless supplied buffer , know how big is. string copying or modifying function work.
  2. it means sequence of numbers returned rand() affected calls rand() function itself: no matter in between calls rand(), you'll same outputs. is, underlying function advanced calls rand(). doesn't mean output increasing.
  3. 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 pointer fileno , 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

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -