Hex Editor
Hex Editor - Binary File Editing Software for Windows

Directives

HHD Software - Hex Editor Serial Port Monitor USB Protocol Analyzer Network Monitor
 
 
 
< PreviousTopNext >

Directives are special commands to the compiler which are only allowed at non-global scope.

$assert Directive

Syntax:

$assert(condition-expression [, message [, fatal-expression]]);
      

Assert directive is evaluated at run-time. First, condition-expression is evaluated. If it evaluates to non-zero value, nothing happens. But if it evaluates to a zero value, message is displayed to the user and structure binding is terminated. If message is omitted, standard "Assertion Failed" message is displayed. message, if present, must be a string expression. fatal-expression, if present, must be a constant expression. If it evaluates to a non-zero value, the assertion is fatal (this is a default behavior), that is, fired assertion terminates structure binding. If it evaluates to zero, assertion is only informational.

Assertions are good at verifying whether the data structure is being bound to correct data.

struct A
{
    int a;
    $assert(5 < a && a < 10,"a must be between 5 and 10");
};
      

$print Directive

Syntax:

$print(var-name-string-expression,var-value-expression);          
        

The first expression must be a constant string expression and serves as a pseudo-field name. This name is displayed in the Structure Viewer Tool Window. It also is added as a real field into the current scope and may be later referenced in expressions. The second expression is a field's value. It may be either a constant expression or a non-const expression, that will be evaluated at run time.

struct A
{
    int a;
    int b;
    $print("double_a",a * 2);
    $print("a/b",double(a)/b);
};
        

Both $print directives in the example above introduce new fields into the current scope (of struct A), but only the first one may be referenced in expressions, because the second one has incorrect name. So, it's OK to use any name for the first argument, but only syntactically correct ones may be referenced in expressions.

$break_array Directive

Syntax:

$break_array(const-conditional-expression);
        

When used in a user-defined type, unconditionally breaks an enclosed array.

The parameter, which must be a constant value, specifies whether the current element should be included into an array (const-conditional-expression = true), or not (const-conditional-expression = false)

May be used either in conjunction with infinite array or with an ordinary array. If used not inside an array, the directive is ignored.

struct StringCharacter
{
    char c;
    if (c==0)
      $break_array(true);
};

struct NullTerminatedString
{
    StringCharacter chars[*];
};
        

$bind Directive

Syntax:

$bind(type-string-expr,var-string-expr,addr-expr);          
        

All directive expressions are evaluated at run time. First two are automatically converted to strings, while the third is expected to be of integer type.

This directive instructs parser to bind another structure to a given address. Binding is delayed until the current structure binding is successfully finished.

You must reference the full type name, for example "struct MyStruct", not the "MyStruct", and the referenced type must have been declared as public.

public struct B
{
// …
};

public struct A
{
    int Offset;
    if (Offset != 0)
        $bind("struct B","pB",Offset);
};
        

$alert Directive

Syntax:

$alert(expr);
        

Evaluates expr at bind time and displays the result in a message box.

< PreviousTopNext >
Copyright © 2012 HHD Software. All rights reserved.