| |

VerySource

 Forgot password?
 Register
Search
View: 632|Reply: 4

Who can explain in detail the "machine-independent types" mentioned in "C ++ primer"?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-19 16:30:01
| Show all posts |Read mode
Who can explain in detail the "machine-independent types" mentioned in "C ++ primer"?

How to make your own programs run in "different operating systems" and "different machines"?

Thank you for your guidance!
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-4-29 17:30:02
| Show all posts
Under each system, the correct implementation of "machine-independent types" is provided.
Reply

Use magic Report

2

Threads

54

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2020-5-1 18:45:01
| Show all posts
Uniform precision data types provided for different platforms
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-4 22:15:01
| Show all posts
Machine independence is a very simple concept. In short, this requires that the effective implementation of a programming language should not depend on the characteristics of a particular set of instructions. Of course, machine independence is always a problem (for example, the C Standards Committee is considering how best to deal with new 64-bit arithmetic machines), with the exception of some particularly noteworthy Remember Java), this great machine-independent ideal has really driven language design for about 30 years. . . . . . . .
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-5 10:00:02
| Show all posts
[Quotation]
Promote cross-platform development
Typedef has another important purpose, which is to define machine-independent types. For example, you can define a floating-point type called REAL, which can achieve the highest precision on the target machine:
typedef long double REAL;
On machines that do not support long double, the typedef will look like this:
typedef double REAL;
And, on machines that do not even support double, the typedef will look like this:,
typedef float REAL;
You can compile this application that uses REAL type on every platform without any modification to the source code. The only thing to change is the typedef itself. In most cases, even this slight change can be achieved automatically by wonderful conditional compilation. Isn't it? The standard library uses typedef extensively to create such platform-independent types: size_t, ptrdiff and fpos_t are examples. In addition, typedefs such as std :: string and std :: ofstream hide long, difficult-to-understand template specialization syntax, such as basic_string, allocator> and basic_ofstream>.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list