Apple Darwin Bedienungsanleitung Seite 21

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 68
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 20
int foo0;
int foo1;
int foo2;
long long bar;
};
#pragma options align=reset
You should use this option only when absolutely necessary, because there is a performance penalty for
misaligned accesses.
Use sizeof with malloc. Since pointers and long integers are no longer 4 bytes long, never call malloc with
an explicit size (for example, malloc(4)) to allocate space for them. Always use sizeof to obtain the correct
size.
Never assume you know the size of any structure (containing a pointer or otherwise); always use sizeof to
find out for sure. To avoid future portability problems, search your code for any instance of malloc that isn't
followed by sizeof. The grep command and regular expressions are your friend, though using Find in the
Xcode Edit menu can do the job.
64-bit sizeof returns size_t. Note that sizeof returns an integer of type size_t. Because the size of size_t
has changed to 64 bits, do not pass the value to a function in a parameter of size int (unless you are certain
that the size cannot be that large). If you do, truncation will occur.
Use explicit (fixed-width) C99 types. You should use explicit types where possible. For example, types with
names like int32_t and uint32_t will always be a 32-bit quantity, regardless of future architectural changes.
Suggested C99 type32-bit type
int8_t or uint8_tchar or unsigned char (only when used as a one-byte integer)
int16_t or uint16_tshort or unsigned short
int32_t or uint32_tint or unsigned int
int32_t or uint32_tlong or unsigned long
int64_t or uint64_tlong long or unsigned long long
Watch for conversion errors. Conversion of shorter types to 64-bit longs may yield unexpected results in
certain cases. Be sure to read Sign Extension Rules for C and C-derived Languages (page 25) if you are seeing
unexpected values from math that mixes int and long variables.
Making Code 64-Bit Clean
Data Type and Alignment Tips
2012-12-13 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.
21
Seitenansicht 20
1 2 ... 16 17 18 19 20 21 22 23 24 25 26 ... 67 68

Kommentare zu diesen Handbüchern

Keine Kommentare