next up previous contents index
Next: The Camera Up: More About C++ Previous: Headers and Pre-Processing   Contents   Index

Comparison with LATEX Syntax

As a programming language, C++ provides certain features common to all languages (such as LATEX, Metapost, Perl, Lisp...) and adheres to rules of grammar. Salient differences between LATEX and C++ include:

  1. Every C++ statement and function call must end with a semicolon. An omitted semicolon may result in a cryptic error message from the compiler. Pre-processor directives, which start with a #, do not end with a semicolon.

  2. Backslash is an escape character in C++:
      // Put label $y=\sin x$ at (2,1)
      // Note single  ^ backslash in output
      label(P(2,1), P(0,0), "$y=\\sin x$"); 
      //       Double backslash ^^ in source
    

  3. Variable and function names may contain letters (including underscore) and digits only, are case sensitive, and must begin with a letter.

  4. Variables in C++ must have a declared type, such as int (integer) or double (double-precision floating point). If a variable has global scope and its value does not change, the definition should probably come in the preamble or at the beginning of main. Local variables should be defined in the smallest possible scope. Unlike C, C++ allows variables to be defined where they first appear.

  5. C++ requires explicit use of * to denote multiplication; juxtaposition is not enough. C++ does not support the use of ^ for exponentiation, e.g., t^2 is invalid. Instead, use t*t or pow(t,2).

  6. C++ has single- and multi-line comments. Everything between a double slash and the next newline is ignored, while the strings /* and */ delimit multi-line comments. A single-line comment may appear within a multi-line comment, but the compiler does not nest multi-line comments.

Between them, C and C++ have about 100 reserved keywords which cannot be used as function or variable names. The script keywords packaged with ePiX is a simple lookup utility, meant to help you avoid name clashes. To find keywords containing the string type, for example, do ``keywords type''.


next up previous contents index
Next: The Camera Up: More About C++ Previous: Headers and Pre-Processing   Contents   Index
Andrew D. Hwang 2004-09-04