Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2010
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2010 by Ivor Horton; ISBN: 9780470500880
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 11th, 2011, 12:59 PM
Registered User
 
Join Date: Feb 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Chapter 2(Ex2_05.cpp) const double - why?

If i'm use in Ex2_05.cpp
Code:
#define rollLength 12.0*33.0
isnt this is equal to
Code:
const double rollLength =12.0*33.0;
from book?
Will there be differences in the compiled program?
If not same, then which of this better to use for better perfomance of program?Or its no point?
Thank you in advance.
P.S. Sorry for my bad language.
 
Old March 28th, 2012, 11:19 AM
Registered User
 
Join Date: Mar 2012
Posts: 12
Thanks: 0
Thanked 3 Times in 3 Posts
Default

There are a few reasons why I would recommend using the "const double" variant in favour of defining a macro.

1. I suspect performance is better as the data type has been explicitly defined.
2. It is more readable and clearer what the type and purpose of the variable is.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Const crmpicco VB How-To 2 May 18th, 2005 09:51 AM
how to make a const do something usefull allee_man VB How-To 2 January 4th, 2005 08:56 AM
passing a const reference in C#.NET texasraven C# 2 December 21st, 2004 06:48 PM
what's the diference between readonly and const?? gbianchi VB.NET 2002/2003 Basics 2 November 11th, 2004 02:53 PM
Const Question Greg Griffiths Classic ASP Basics 1 June 30th, 2003 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.