Thread: Using cin with 8-bit integers?

  1. #16
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Many of us flounder from time to time when making an analogy.

  2. #17
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    Good cod, this isn't the plaice to make mistakes.

  3. #18
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by Hobbit View Post
    Good cod, this isn't the plaice to make mistakes.
    Holy mackerel!

  4. #19
    Registered User
    Join Date
    Jun 2016
    Posts
    40
    Quote Originally Posted by algorism View Post
    The quote says exactly the opposite of your point.
    I don't see how :/

    Quote Originally Posted by jimblumberg View Post
    Undefined behavior means anything can happen, from appearing to work properly to crashing your system or worse.
    Oh, like what happens when you try to access element 5 in an array with only three elements.

    Quote Originally Posted by jimblumberg View Post
    You're kidding right? If you don't know what a processor is you really really should consider another profession. It just happens to be the heart and sole of your, and everyone else's, computer.

    Jim
    I know what a processor is; I don't know how you came to think I didn't :/

  5. #20
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by Tesp View Post
    I don't see how :/
    What can I do?
    This is a programming site, not an English site.
    I have neither the time, inclination, nor skill to hold your hand and walk you through the sentences.
    Try google-translating it into your native language (though that will probably make it worse).

  6. #21
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    Tesp the quote basically says the times you need to worry about saving every byte you can are few and far between. You shouldn't worry about it especially whilst learning C++. By the time you need to do it, if that ever occurs, you will know how to comfortably.

    Are you familiar with the structure of a processor? And how processors fetch data from memory? The read/modify/write cycle?
    If not you should certainly increase your knowledge in this area, especially as C++ allows you to inline assembly language in your code which can sometimes be helpful especially if you ever come to write game engines.

    Undefined behaviour is simply that. It is something the rules of the language allow syntactically but isn't defined by the C++ standard so anything could happen, all bets are off. You should keep your code so that behaviour is defined, so that you know exactly what it will do.

  7. #22
    Registered User
    Join Date
    Jun 2016
    Posts
    40
    Quote Originally Posted by Hobbit View Post
    Tesp the quote basically says the times you need to worry about saving every byte you can are few and far between. You shouldn't worry about it especially whilst learning C++. By the time you need to do it, if that ever occurs, you will know how to comfortably.

    Are you familiar with the structure of a processor? And how processors fetch data from memory? The read/modify/write cycle?
    If not you should certainly increase your knowledge in this area, especially as C++ allows you to inline assembly language in your code which can sometimes be helpful especially if you ever come to write game engines.

    Undefined behaviour is simply that. It is something the rules of the language allow syntactically but isn't defined by the C++ standard so anything could happen, all bets are off. You should keep your code so that behaviour is defined, so that you know exactly what it will do.
    Understood about the processors and behavior definedment, Hobbit I'm not familiar with how processors work (not much beyond them being computers' brains, anyway), but I'll look into them.

  8. #23
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Well, you don't need to know how a processor works in detail unless you're doing some significant super duper low-level optimizations. More often than not (in my opinion), it's most worthwhile to understand that fetching RAM can be slow compared to a processor's native clock speed and what things like cache coherency are.

    Node.js took the world by storm because the web isn't compute-heavy because more often than not, you're bottlenecked by the speed of your HDD. This means that in all reality, one compute thread really can handle most of the load.

    Granted, I don't think most people who do Node understand this detail because the marketing surrounding it was brilliant but this is the logical explanation for why Node is "good" and is what also makes it "bad" in certain contexts.

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Hobbit View Post
    Are you familiar with the structure of a processor? And how processors fetch data from memory? The read/modify/write cycle?
    If not you should certainly increase your knowledge in this area, especially as C++ allows you to inline assembly language in your code which can sometimes be helpful especially if you ever come to write game engines.
    A beginner isn't trying to write game engines, are they now? This stuff is absolutely not necessary to know for beginners. This is an advanced topic that dives into computer architecture, an entirely different area of knowledge. Avoid focusing on this area until you have a good understanding of the language and are thinking of moving into areas where optimization is absolutely necessary. This stuff isn't easy.
    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.

  10. #25
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    Quote Originally Posted by Elysia View Post
    A beginner isn't trying to write game engines, are they now? This stuff is absolutely not necessary to know for beginners. This is an advanced topic that dives into computer architecture, an entirely different area of knowledge. Avoid focusing on this area until you have a good understanding of the language and are thinking of moving into areas where optimization is absolutely necessary. This stuff isn't easy.
    Nobody is suggesting learning to program in assembly language, just the general principles of how a processor works, and how memory is read and written. It's fundamental knowledge for any programmer of a reasonably low level general purpose language such as C or C++.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, it's not

    It depends on your field.
    Last edited by Elysia; 12-21-2016 at 01:17 PM.
    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.

  12. #27
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    No, it's not.
    Well, it depends.

    Things that I've found are useful are knowing that every time you malloc, you're asking the kernel for a region of memory. This can become problematic in multithreaded code where you have many malloc calls. This place helped me write genuinely faster multithreaded code exactly because I learned about how to manage my own memory and take that burden off of the kernel.

    It's also important to know why cache coherency can yield faster code, here the reason being that a RAM fetch is typically on the order of hundreds of CPU cycles for a GHz processors so your CPU will idle or maybe something else will be scheduled and then you have this other mess with other threads running and waiting for yours to be scheduled once again.

    It's more about writing code that's friendlier towards your OS than your hardware, imo. But it is somewhat necessary to understand the basics like this.

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't deny that understanding hardware makes you able to write faster programs. But my point is, unless it's necessary to do so, you don't need to optimize for the hardware. Doing so creates more complicated code that's harder to read, debug and understand.

    So if you're just writing scripts or having fun or if your program is so fast performance doesn't matter, knowing these things is just a waste of time. C++ is a general purpose language. It can run in many contexts, so some contexts don't require this type of knowledge, and some do.
    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.

  14. #29
    Old Took
    Join Date
    Nov 2016
    Location
    Londonistan
    Posts
    121
    The basics you ought to understand are stuff like what a register is, what the stack pointer is, how stack memory works and why it's different to the heap. You absolutely must understand the RMW cycle before getting into multithreaded code especially now that there's atomic classes and thread classes. You can get by not understanding how to program for specific processors, but you should have a general knowledge of how processors work.

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Hobbit View Post
    what a register is
    I completely fail to understand why one ought to understand this one. Good for optimization, but most people don't need to do these advanced optimizations.

    what the stack pointer is
    Same here.

    how stack memory works and why it's different to the heap
    It is true that as a C++ dev, you need to know the difference between the stack and heap, but beyond that, you don't need to know more.

    You absolutely must understand the RMW cycle before getting into multithreaded code especially now that there's atomic classes and thread classes
    Multi-threading with data sharing is an advanced topic, so that requires you to specialize in the area, so to speak. But it's not a topic everyone needs to know.

    ...but you should have a general knowledge of how processors work.
    Not necessary.

    And just as a disclaimer: I am claiming this is not necessary basics for every C++ programmer. People who work in specific fields or do advanced stuff like game engines or threading needs to know more than just the basics. Those people need to know this stuff, but they are not every C++ dev.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-26-2012, 10:50 AM
  2. integers... help
    By rikari in forum C Programming
    Replies: 3
    Last Post: 12-10-2009, 10:24 PM
  3. need help with integers
    By tomisme in forum C Programming
    Replies: 10
    Last Post: 05-29-2008, 01:04 AM
  4. 20 integers
    By bazzano in forum C Programming
    Replies: 11
    Last Post: 04-03-2007, 08:06 AM
  5. Integers
    By Marky_Mark in forum Windows Programming
    Replies: 1
    Last Post: 11-26-2001, 04:56 PM

Tags for this Thread