FutureBasic Logo

<<    Index    >> FutureBasic

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.

C functions Example

// 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 the translator

In your FB source, FooBeep may now be used instead of the keyword beep.


C global variables

Defined constants (_myConst, _versionPascalString) 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 _versionPascalString. 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 the translator

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

// 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 symbol for the translator
toolbox BuildWindow

BuildWindow

HandleEvents

See also
BeginCCode; BeginCFunction; EndC