HP SunSoft Pascal 4.0 Manual do Utilizador Página 148

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 333
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 147
124 Pascal 4.0 Users Guide
6
The -calign option is not needed for this example, but may be necessary if
the array parameter is an array of aggregates.
Records and Structures
In most cases, a Pascal record describes the same objects as its C structure
equivalent, provided that the components have compatible types and are
declared in the same order. For more information, see “Compatibility of Types
for C and Pascal” on page 90.
Records that contain aggregates may differ because aggregates in C and Pascal
sometimes have different sizes and alignments. If you compile the Pascal code
with the -calign option, the differences are eliminated.
A Pascal record of an integer and a character string matches a C structure of an
integer and an array of char values, as follows:
The commands to compile and
execute IntCA.c and
IntCAMain.p
hostname% cc -c IntCA.c
hostname% pc -calign IntCA.o IntCAMain.p
hostname% a.out
444
The C function, StruChr.c #include <string.h>
struct TVarLenStr {
int nbytes;
char a[26];
};
void StruChr(struct TVarLenStr *v)
{
strncpy(v->a, "strvar", 6);
v->nbytes = 6;
}
Vista de página 147
1 2 ... 143 144 145 146 147 148 149 150 151 152 153 ... 332 333

Comentários a estes Manuais

Sem comentários