Problem with .write() function

This is a discussion on Problem with .write() function within the C++ Programming forums, part of the General Programming Boards category; Yes, they don't behave the same on all platforms. O_o You and MK27 should not be allowed to give advice ...

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,165
    Yes, they don't behave the same on all platforms.
    O_o

    You and MK27 should not be allowed to give advice regarding IO issues at any level.

    Do you not realize that a text file, an ASCII file to offer a specific example, is a binary file with a particular interpretation? What about PNG, JPG, and DB3? Do you know any of those file formats? Do you think that they are text files? Ever hear of a "byte order mark" or "variable byte integers"?

    Yes, they don't behave the same on all platforms.
    By your logic, neither are the standard streams. You should consider other forms of encoding the same character. Take a platform writing EBCDIC instead of ASCII. The EBCDIC text file produced by one platform is not "native" to platform expecting ASCII.

    Soma

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Are we going to clash about the definition of a binary file? It sounds to me that according to your definition, all files are binary files. They just follow a certain byte order, or a certain interpretation format.
    According to me, a binary file is a file where you have simply written down the bytes of a variable as-is without any regard to external factors such as endianess.
    So I stand by my point that they aren't portable: you cannot expect to write an integer and read it back the same way on all platforms.
    But we could write a binary file and read it back in a controlled way, as you suggest. It would work, but it's still not entirely portable. Semi-portable it is, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by Elysia View Post
    So I stand by my point that they aren't portable: you cannot expect to write an integer and read it back the same way on all platforms.
    An MP3 file isn't portable? I feel like we've been down this road before.

    I also have a definition for simply writing data to a file without regard for endianness or other portability issues: it's called "stupidity."
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Quote Originally Posted by brewbuck View Post
    An MP3 file isn't portable? I feel like we've been down this road before.
    By my definition of binary file, that is not a binary file because it follows a certain expected byte pattern.

    I also have a definition for simply writing data to a file without regard for endianness or other portability issues: it's called "stupidity."
    ...And that is what I have been trying to say: binary files (my definition) aren't portable. They are semi-portable. That is, it is possible to do it, but it might not be a good idea.
    (Which is why I wanted to discourage the write function, which phantomotap complained about.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    Redefining things will not make you more correct.

  6. #21
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,165
    I also have a definition for simply writing data to a file without regard for endianness or other portability issues: it's called "stupidity."
    Ignorance at best.

    By my definition of binary file, that is not a binary file because it follows a certain expected byte pattern.
    That is an incredibly stupid definition... the ultimate in stupid definitions. If you dump a "little endian" integer of four bytes it follows an expected byte pattern by definition.

    And that is what I have been trying to say: binary files (my definition) aren't portable.
    Which is why I wanted to discourage the write function, which phantomotap complained about.
    ENOUGH OF THIS! You are either foolish or a liar

    It does not matter what definition of "binary file" you use, you can not use "text mode" of the C or C++ standard library IO facilities to create examples of either kind because these facilities are allowed to translate the binary patterns sent to them.

    [Edit]
    To make the above clearer, you are wrong no matter the definition you choose to use.
    [/Edit]

    So, which is it?

    Soma
    Last edited by phantomotap; 07-05-2010 at 09:42 AM. Reason: none of your business

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Quote Originally Posted by whiteflags View Post
    Redefining things will not make you more correct.
    No one has provided any better definition.

    But enough of this. Regardless of who is correct, I think this discussion has brought to light that problematics behind the original problem, on both sides of the argument.
    One can reasonably get an understanding of the pros and cons by reading this, and that is sufficient.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tough problem with function pointers
    By Montejo in forum C Programming
    Replies: 10
    Last Post: 12-22-2009, 12:17 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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