Thread: Help with claims

  1. #1
    Registered User
    Join Date
    Feb 2022

    Help with claims

    i am beginner in c and there are two claims i dont know if they are true

    1.To read bytes you can use system call "read", but it is recommended to read one byte in each reading, and not read all the houses together.

    2.When you want to save memory, you can use bit-field. This way you can "pack" several objects in one memory word and refer to the address of each bit, using the "&" address operator.
    thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    The first is at best dubious. There might be odd cases where reading 1 byte at a time may be useful, but as a blanket rule, it's false.

    The second is out and out rubbish. Bit fields can't be addressed with &.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    Arizona, USA
    1. I'm not sure where you got the recommendation to read one byte at a time with the "read" system call. It's very common to read a large buffer full at a time to minimize overhead (system calls are "slow" compared to user code).

    2. Bit fields are not addressable. The smallest addressable unit in C is char.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    For #2, I'd guess that you have mixed up the address-of operator with the bitwise and operator. They both use the & symbol but with very different syntax and semantics.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Funny Insurance Claims
    By C_Coder in forum A Brief History of
    Replies: 0
    Last Post: 07-13-2002, 07:38 AM

Tags for this Thread