
|
<<
Index
>>
|
FutureBasic 5
|
BeginCFunction
|
|
statement
|
|
Syntax:
BeginCFunction
C statements
EndC
Description:
Marks the beginning of a block of C language statements. 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. BeginCFunction
is intended to replace and has advantages over the old #if def _PASSTHROUGHFUNCTION / #endif
syntax. The #if def _PASSTHROUGHFUNCTION / #endif
syntax continues to be available.
Unlike #if def _PASSTHROUGHFUNCTION / #endif
, BeginCFunction
does not interfere with editor indentation and C keywords within the block are not highlighted.
#if def _PASSTHROUGHFUNCTION
// FBtoC sees this; FutureBasic does not
// FBtoC passes everything, except comments, untranslated to the compiler
// the C code, typically a function definition, goes before main()
#endif
could be written as:
BeginCFunction
// FBtoC passes everything, except comments, untranslated to the compiler
// the C code, typically a function definition, goes before main()
EndC
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; BeginCDeclaration; EndC; #if