What is the meaning or the use of the following lines in a .bi file
#Ifndef __DirExists_bi__
#define __DirExists_bi__
......
......
......
#endif
I think it is to see if a bi file already is 'defined'.
Never seen it used in code though.
Maybe you can give me a sample of how it can be used.
Thanx in advance.
Explanation please
it's a preprocessor macro. if __DirExists_bi__ has not yet been defined (#define __DirExists_bi__ ) then whatever code it between the #ifndef and #endif statement will be compiled into the exe, on the other hand, if __DirExists_bi__ has already been defined, then the code block will be ignored by the compiler.
The reason for it is because sometimes different headers will have the exact same code segments in them. Using this prevents program bloat by making sure that the code is only compiled into the exe once.
The reason for it is because sometimes different headers will have the exact same code segments in them. Using this prevents program bloat by making sure that the code is only compiled into the exe once.
-
- Posts: 2428
- Joined: Jul 19, 2006 19:17
- Location: Sunnyvale, CA
- Contact:
The # prefix means it is a preprocessor statement.
In this use, it means, suppose some one used this line twice:
#include "DirExists.bas"
#include "DirExists.bas"
That would put all of the code from DirExists into your program twice, which would cause duplicates (ie every variable would be created twice). But with the code you have posted, DirExists will only be included in the program once.
Note that ifndef means "if not defined." ;-)
In this use, it means, suppose some one used this line twice:
#include "DirExists.bas"
#include "DirExists.bas"
That would put all of the code from DirExists into your program twice, which would cause duplicates (ie every variable would be created twice). But with the code you have posted, DirExists will only be included in the program once.
Note that ifndef means "if not defined." ;-)
Yep i understand it now.
I use compiler directives when code isn't finished yet
Like the following code:
When the code is finished replace #if 0 with #if 1 or delete it and don't forget to delete the corresponding #endif
I use compiler directives when code isn't finished yet
Like the following code:
Code: Select all
#ifndef __CloseDir_bi__
#define __CloseDir_bi__
#if 0 ' the following code isn't finished (yet), so it won't be compiled
Sub CloseDir
_Findclose(DirHandle)
DirInUse = 0
end Sub
#endIf
#endif
If I understand you correctly;wallace wrote:Because large projects get modulated and often lots of them all include the same header file. #defining it makes sure that the compiler doesn't add the header more than once in that case.
Using #include once does not prevent a file from being included more than once in a multi-module compile, but does in a single module compile.
Is this accurate?
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Each module in your program can include the header once.elsairon wrote:If I understand you correctly;
Using #include once does not prevent a file from being included more than once in a multi-module compile, but does in a single module compile.
Is this accurate?
It's entirely possible (indeed, probable) that multiple modules will want to use the same header file, so it's a case of "whichever modules want the header, they each get it once", rather than "the first module can have the header, the others, go fish".
#include once should have the same effect as "#ifndef whatever ... #define whatever .. #endif" (the define is only remembered for the duration of the module), Except one is indicated by the including code, and one is indicated by the included code.
"#pragma once", as cha0s suggests, is a simpler, less hackish way of doing "#ifdef ... #endif" in the included code.
All three work for the duration of the module, so can be used for multi-module projects.
(Conveniently, the "per-module" scope means the compiler doesn't have to remember, between modules, whether a header has been used or not. This would be particularly difficult if you don't compile all the modules at the same time :)