Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Global Constants (http://www.chiefdelphi.com/forums/showthread.php?t=24308)

Mike Betts 07-02-2004 11:40

Re: Global Constants
 
Quote:

Originally Posted by Darkman_X000
In C++ you can declare global constants using const varType varName = initialValue; Is this acceptable in C?

Please clarify!!!

Please read the pdf document MPLAB® C18 C COMPILER USER’S GUIDE which was included on the CDROM that had MPLAB. All your questions will be answered.

Beware comparing C++ with C. C has been around since 1974 and has changed very little in all these years. ANSI complient C is a standard and C++ is a different animal.

Adam Shapiro 08-02-2004 11:34

Re: Global Constants
 
Quote:

Originally Posted by Darkman_X000
What exactly do you mean by "globally-included header file"? When you use #define to create a global constant, it does not have a type. Do you have to typecast it whenever you use it?

I meant that you can use a #define statement in a header (for example "globals.h") that is included in any file that needs that variable. When you use a #define statement the variable name that you create will be replaced later (not sure of which but either by the compiler or the linker..probably compiler). Hence, the variable that you create with #define would be constant, you can not modify it. You can, however define variables using extern which would be globally accessable (see 'Global Variables, anyone?').

Quote:

Originally Posted by Darkman_X000
In C++ you can declare global constants using const varType varName = initialValue; Is this acceptable in C?

Unfortunately I am more of a C++ programmer, myself, so I do not really know an answer to this one. Perhaps somebody else can field this question?'Global Variables, anyone?'

Astronouth7303 08-02-2004 19:05

Re: Global Constants
 
If it is in a header, then you can is a const in any file that includes the header


All times are GMT -5. The time now is 14:16.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi