IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC++/CLILanguage Basics  Print This     

Literals (Cross Ref > Language Basics)

By Mike Prestwood

C++/CLI versus Delphi Prism: A side by side comparison between C++/CLI and Delphi Prism.

 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Literals

[Other Languages] 

General Info: Programming Literals

A value directly written into the source code of a computer program (as opposed to an identifier like a variable or constant). Literals cannot be changed. Common types of literals include string literals, floating point literals, integer literals, and hexidemal literals. Literal strings are usually either quoted (") or use an apostrophe (') which is often referred to as a single quote. Sometimes quotes are inaccurately referred to as double quotes.

Languages Focus

In addition to understanding whether to use a quote or apostrophe for string literals, you also want to know how to specify and work with other types of literals including floating point literals. Some compilers allow leading and trailing decimals (.1 + .1), while some require a leading or trailing 0 as in (0.1 + 0.1). Also, because floating point literals are difficult for compilers to represent accurately, you need to understand how the compiler handles them and how to use rounding and trimming commands correctly for the nature of the project your are coding.

C++/CLI:   qoute

Same as standard C++. String literals are quoted as in "Prestwood". If you need to embed a quote use a slash in front of the quote as in \".

To specify a floating point literal between 1 and -1, you can preceed the decimal with a 0 or not (both work). In other words, preceding and following decimals are allowed (both .1 and 0.1). Trailing decimals are also allowed (1, 1., and 1.0 are all equivalent and allowed).

Syntax Example:
MessageBox::Show("Hello");
MessageBox::Show("Hello \"Mike\".");
  
//Does ASP evaluate this simple
//floating point math correctly? No! 
if ((.1 + .1 + .1) == 0.3) {
MessageBox::Show("Correct");
} else {
MessageBox::Show("Not correct");
}
Delphi Prism:   quote or apostrophe

In Prism, you use either quotes or apostrophes for string literals.

Different than Delphi, you can start floating point literals with a decimal or an integer. For example, to specify a fractional floating point literal between 1 and -1, you can preceed the decimal with a 0 or not.

x := .1 + .1;     //Does work.
x := 0.1 + 0.1;   //Does work.
Syntax Example:  
MessageBox.Show('Hello');
MessageBox.Show("Hello");

//Example of embedding quotes and apostropes:
MessageBox.Show('He said, "Who''s computer?"');
MessageBox.Show("She said, ""Mike's computer"".");












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]