
|
<<
Index
>>
|
FutureBasic 5
|
BeginCDeclaration
|
|
statement
|
|
Syntax:
BeginCDeclaration
C declarations or preprocessor directives
EndC
Description:
Marks the beginning of a block of C language statements and is typically used to pass an #include statement to a translated .h file, for example:
BeginCDeclaration
#include <OpenGL/glu.h>
EndC
The block must be terminated with the EndC
statement. The C statements are copied untranslated into the C source code, then compiled by the C compiler.
Example:
C functions
// declarations of all kinds (these go in *.h)
BeginCDeclaration
void FooBeep();
EndC
// definitions of functions and global vars (these go in *.c)
BeginCFunction
void FooBeep()
{
SysBeep( 1 );
}
EndC
toolbox FooBeep() // declare symbol for FBtoC
In your FB source, FooBeep may now be used instead of the keyword beep.
C global variables
Defined constants (_myConst, _versionString$) are in general preferred to literals (42, "1.3"), for reasons of readability and ease of maintenance. The example shows how to obtain the CFString equivalent of _versionString$. A global CFStringRef is initialized at compile time, and given the "const" attribute so that it cannot be modified at run time.
// declarations of all kinds (these go in *.h)
BeginCDeclaration
extern const CFStringRef kFooVersionString;
EndC
// definitions of functions and global vars (these go in *.c)
BeginCFunction
const CFStringRef kFooVersionString = CFSTR( "1.3" );
EndC
system CFStringRef kFooVersionString // declare symbol for FBtoC
In your FB source, kFooVersionString may now be used instead of @"1.3" or fn CFSTR( "1.3"), with exactly the same effect.
Objective-C
compile as "Objective-C"
// declarations of all kinds (these go in *.h)
BeginCDeclaration
@interface FooThing : NSObject {
NSWindow *window;
}
- (void)buildWindow;
@end
void BuildWindow( void );
EndC
// definitions of functions and global vars (these go in *.m)
BeginCFunction
@implementation FooThing
- (void)buildWindow {
window = [[NSWindow alloc] initWithContentRect:NSMakeRect( 0, 0, 300, 300 )
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered defer:NO];
[window center];
[window setTitle:@"FooThing"];
[window makeKeyAndOrderFront:nil];
}
@end
void BuildWindow( void )
{
FooThing *ft = [[FooThing alloc] init];
[ft buildWindow];
[ft release];
}
EndC
// declare symbols for FBtoC
toolbox BuildWindow
toolbox fn NSApplicationLoad = Boolean
// main
fn NSApplicationLoad()
BuildWindow()
RunApplicationEventLoop()
See Also:
BeginCCode; BeginCFunction; EndC; #if