View Poll Results: Who agrees with me that this thread should die?

Voters
5694. You may not vote on this poll
  • Should die now

    5,694 100.00%
  • Should let message board nature take it down the list

    0 0%

Thread: Clearing the console

  1. #16
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    I still think it's a good habit to get into. In fact, I know it is. C++ is all about systems programming, so eventually you'll get into compiler design, interpreters, device drivers, operating systems, editors, file utilities, and performance executives that will need the register keyword. Think outside of MS's compilers. There's a whole different world out there where you shouldn't second-guess each compiler (and there's tons of older ones you'll need to use eventually). If it ignores the register keyword, big deal. At least you sent a request, and that's better than not doing so. That's why it's a good habit to get into - it's good practice, and it shows that you care about a possible performance boost, or some special treatment from the compiler.

    This is Microsoft specific if you have Visual C++:
    The compiler does not accept user requests for register variables; instead, it makes its own register choices when global register-allocation optimization (/Oe option) is on. However, all other semantics associated with the register keyword are honored.
    Last edited by dxfoo; 09-07-2005 at 03:20 PM.

  2. #17
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Honestly I think thats kinda bogus dxfoo, hate to say it, but the register part of the for loop is a trivial optimization at best.

    C++ is NOT just about systems programming... I see it more as a fast, very flexible programming language. It has its root in systems programming for sure, but there are many things which take an even higher level language. Just for a note, I am a systems programmer, and generally we use it in everyday apps more than we use for basic systems programming.

    But in any event, back to the thread at hand, the cprogramming faq has a lot of good things in it, I would suggest searching it, then asking for help, it can help save your time as well
    Last edited by dpro; 09-07-2005 at 03:38 PM. Reason: Removing a line which made no sense.

  3. #18
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    "However, all other semantics associated with the register keyword are honored." - RTFM.

    Register would work in this for-loop situation, because by default, Microsoft IDE's leaves the /Od and /Oe option unchecked.

    If you want Microsoft to allow this optimization, for example with VC++ 2005, go to project-> Properties -> Configuration -> C/C++ -> Optimization -> Optimization setting = "Full Optimization".

    The default option is "DISABLED (/0d)." Even /0e is disabled. (RTFM again or look at MS's quote above in my other post in how it relates to /0e).

    I give information. You can either listen, look into it more, or waste time arguing.
    Last edited by dxfoo; 09-07-2005 at 04:07 PM.

  4. #19
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    C++ is all about systems programming, so eventually you'll get into compiler design, interpreters, device drivers, operating systems, editors, file utilities, and performance executives that will need the register keyword.
    Says who? Yes, C++ has a strong foundation in systems programming, but it's also popular with applications programmers that don't give one whit about the register keyword, and shouldn't. I think your priorities are seriously misplaced. If you find yourself on a compiler that honors your hint and it actually improves performance, you probably need to do some higher level optimizations before trying to micromanage everything. Use better algorithms first, then look to the smaller stuff. I mean really, if you need control over your registers, why aren't you using assembly?
    I give information. You can either listen, look into it more, or waste time arguing.
    You offer information, I offer experience. Unless your title is a lie, you could benefit from it.
    Just because I don't care doesn't mean I don't understand.

  5. #20
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    I just gave you hard proof that register is necessary because /0e is not enabled by default. Microsoft quotes, for the 3rd time, "...instead, it makes its own register choices when global register-allocation optimization (/Oe option) is on." Why is there an arguement when this is coming directly from the manual?

  6. #21
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Lol because its not necessary. Would you stick a band-aid on your thumb before you might cut yourself? It shouldn't be in the realm of this conversation because it has no bearing on clearing a console. Optimization comes last, after bugs/fixes have been worked out. Small optimizations like this are low priority, and generally unnecessary. More importantly as narf said, algorithms come first, then simple things such as register(if even needed). Anyway, this is silly to argue about... use register if you want, but pay attention to the more important things first.

  7. #22
    Software engineer
    Join Date
    Aug 2005
    Location
    Oregon
    Posts
    283
    You guys assumed register was ignored by the compiler, and I personally found you guys ignorant when I even proved this wrong. Evn five posts later! Yes, it was necessary to explain because you guys do not understand Microsoft's compiler when it comes to the register keyword. Now that it's explained, you guys are slowing down the program without registers as loop-control variables. Follow my directions, and the register keyword will only help optimize your pogram. I'm referring to his for-loop. If he uses register, it will give him a better performance boost. That's all I was pointing to lol.

    Listen, next time you want to argue that applying register won't have any effect, RTFM! Why can't you apply what I quoted? It should have ended this needless conversation an hour ago.
    Last edited by dxfoo; 09-07-2005 at 04:59 PM.

  8. #23
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Oh, please, dxfoo, stop preaching! You're just making yourself look ridiculous.

    Give me one good reason why I would not enable global optimizations for my release build.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #24
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Why is there an arguement when this is coming directly from the manual?
    I'm not arguing that register might have an effect. I'm telling you that you're focusing on the wrong things for optimization. But if you really want to keep talking about register, I refuse to listen until you have the "hard proof" from a profiler showing that not only is there an improvement in speed, but that there's a significant improvement that warrants using register without even considering that a far better improvement could be had by using better algorithms.

    See the difference? You're talking from theory--probably from one of your classes--and I'm talking from practical experience in the real world. Please don't take offense. I'm just trying to give you another perspective.
    If he uses register, it will give him a better performance boost.
    You'd be wise to avoid absolutes. Not only could register not give him better performance, it could be slower. It's been repeatedly proven that the compiler is way smarter than the programmer when it comes to placing variables in registers. Yet people still try to pretend that they can magically find performance optimizations just by looking at tiny snippets of code. In practice, it's generally better to err on the side of simplicity, then optimize when you can prove that there's a speed problem.
    I hope you guys start listening more. You might learn something.
    Feel free to be offended at my next statement, but if you have any personal attacks, direct them to my private messages.

    You should spend more time listening and less time trying to defend your position. If you're too busy talking, you miss the valid points that are being made, and you remain ignorant.
    Just because I don't care doesn't mean I don't understand.

  10. #25
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Of course here is a very simple way to clear up this silly argument -- have the compiler produce an assembly listing of the program with and without use of register keyword. In the test I made with VC++ 6.0 release build it made no difference, both programs produced the exact assembly program. I even tried adding other stuff in the function to see what affect additional integers had -- none. The compiler still used a register for loop counters whether I used register keyword or not.

    Of course other compilers may nor may not have the same affect.

  11. #26
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Eitehr way, I think it's a good habit to get into, because there's so many systems out in the world that depend on C/C++ code.
    For speed purposes, do the following:

    Understand the difference between writing a simple program on your PC to help you learn C++, and writing a program intended to be run on a microcontroller.

  12. #27
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I tested with VC7. The register keyword made no difference, either with optimisation turned on or off.

    Unoptimized assembly:
    Code:
    ; 5    : 	register int i;
    ; 6    : 
    ; 7    : 	for (i = 0; i < 50; i++)
    
    	mov	DWORD PTR _i$[ebp], 0
    	jmp	SHORT $L794
    $L795:
    	mov	eax, DWORD PTR _i$[ebp]
    	add	eax, 1
    	mov	DWORD PTR _i$[ebp], eax
    $L794:
    	cmp	DWORD PTR _i$[ebp], 50			; 00000032H
    	jge	SHORT $L792
    Optimized (/02) assembly:
    Code:
    ; 5    : 	int i;
    ; 6    : 
    ; 7    : 	for (i = 0; i < 50; i++)
    
    	mov	esi, 50					; 00000032H
    $L864:
    
      // Loop contents omitted.
    
    ; 5    : 	int i;
    ; 6    : 
    ; 7    : 	for (i = 0; i < 50; i++)
    
    	dec	esi
    	jne	SHORT $L864

  13. #28
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Think outside of MS's compilers.
    I've seen no evidence that you have.

    > where you shouldn't second-guess each compiler
    So why insist on pointless micro-optimisations like using 'register', which a lot of optimisers simply ignore nowadays.

    > it's good practice, and it shows that you care about a possible performance boost
    No, choosing good algorithms counts. No amount of 'register' will save your bubble sort from being pounded into the ground by any half-decent quicksort. You're focussing on the wrong issue.

    > Microsoft quotes, for the 3rd time, ".
    Once again, you're trying to extrapolate the universe from one specific implementation. I don't give a rats ass what YOUR compiler says about register, this board caters for all compilers / operating systems, so stop preaching what "my" compiler does as being the best advice for everyone else.
    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.

  14. #29
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    He'll learn when the real world bites him. After all, as a CS student he's bullet proof. Us old hacks that have actually been doing the job for real money in the real world for years know nothing.

    Where's that damned rep button when you need it.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  15. #30
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Hey I am a CS student and I listen to my elders
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  2. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 03:44 AM
  3. Clearing the screen in a dos console window...
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 02-15-2002, 04:15 AM
  4. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM
  5. clearing an NT console
    By iain in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2001, 01:08 PM