BUFSIZ value

This is a discussion on BUFSIZ value within the C Programming forums, part of the General Programming Boards category; I noticed that the BUFSIZ macro in stdio.h contains different values for different compilers for the same platform (windows). gcc ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    201

    BUFSIZ value

    I noticed that the BUFSIZ macro in stdio.h contains different values for different compilers for the same platform (windows).

    gcc uses 1024
    VS6 512 or 4096
    some older borland compiler i saw used 2048

    Anybody knows why this is different each time? Shouldnt there be one value which fits best for a certain platform?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The C standard specifies the minimum size. You're allowed to have it larger than that.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    134
    There is no Specific reason behind different values of BUFSIZE from C standard side. Its depends on the compiler developer that what size he find suitable.
    S_ccess is waiting for u. Go Ahead, put u there.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    From http://www.delorie.com/gnu/docs/glibc/libc_226.html:
    Macro: int BUFSIZ
    The value of this macro is an integer constant expression that is good to use for the size argument to setvbuf. This value is guaranteed to be at least 256.

    The value of BUFSIZ is chosen on each system so as to make stream I/O efficient. So it is a good idea to use BUFSIZ as the size for the buffer when you call setvbuf.

    Actually, you can get an even better value to use for the buffer size by means of the fstat system call: it is found in the st_blksize field of the file attributes. See section 14.9.1 The meaning of the File Attributes.

    Sometimes people also use BUFSIZ as the allocation size of buffers used for related purposes, such as strings used to receive a line of input with fgets (see section 12.8 Character Input). There is no particular reason to use BUFSIZ for this instead of any other integer, except that it might lead to doing I/O in chunks of an efficient size.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Different compilers may compile the same code differently, even on the same platform. (Try it: compare gcc/vc/icc generated asm side by side, and maybe repeat with optimization switches.)
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BUFSIZ question
    By Ash1981 in forum C Programming
    Replies: 2
    Last Post: 02-05-2006, 10:11 AM
  2. Newb With Small Pointer Issue
    By G-Prime in forum C Programming
    Replies: 7
    Last Post: 09-06-2004, 05:09 PM
  3. Fgets problem again
    By MethodMan in forum C Programming
    Replies: 5
    Last Post: 02-29-2004, 12:32 AM
  4. What size exactly is the constant BUFSIZ
    By Zahl in forum C++ Programming
    Replies: 2
    Last Post: 04-27-2003, 12:20 PM
  5. Bufsiz
    By steviecrawf in forum C Programming
    Replies: 1
    Last Post: 11-14-2001, 04:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21