|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2002
Città: Roma
Messaggi: 1502
|
Sintassi C
Salve, vorrei avere un chiarimento sulla sintassi del C. In particolare vorrei sapere cosa rappresenta:
__attribute__((__cdecl__)) Questa espressione la si trova nelle dichiarazioni di tipo di variabili e di funzioni negli header della libreira standard, però non ho capito che funzione ha __attribute__, dal punto di vista sinttattico, ad esempio nella dichiarazione di prototipo: Codice:
FILE* __attribute__((__cdecl__)) fopen (const char*, const char*); Codice:
typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); qual è il significato sintattico dei vari termini? Come compilatore ho usato il gcc e il mingw. Altri identificatori che appaiono sono __extension__, per esempio: Codice:
__extension__ typedef int __intptr_t; Inolte nella dichiarazione: Codice:
typedef int (*__gconv_trans_init_fct) (void **, const char *); __gconv_trans_init_fct come il tipo di puntatore a funzione che prende come argomenti un void** e un char* e restituisce un int, giusto? Tra l'altro vorrei sapere se tale codice è codice standard, oppure si tratta di estensioni e parole chiavi devi vari compilatori; cioè se un espressione come: Codice:
typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); Il tutto mi serve per un traduttore di codice C che deve quindi fare anche un po di parsing e quindi vorrei capire cosa fa parte della grammatica del C e cosa no, e se sapete dove posso trovare una specifica formale della grammatica del C adottata dal gcc. grazie e ciao. programma di parsing di codice C
__________________
Sun Certified Java Programmer EUCIP Core Level Certified European Certification of Informatics Professionals |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Microsoft Specific —>
This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention. Element Implementation Argument-passing order Right to left Stack-maintenance responsibility Calling function pops the arguments from the stack Name-decoration convention Underscore character (_) is prefixed to names Case-translation convention No case translation performed Note For related information, see Decorated Names. Place the __cdecl modifier before a variable or a function name. Because the C naming and calling conventions are the default, the only time you need to use __cdecl is when you have specified the /Gz (stdcall) or /Gr (fastcall) compiler option. The /Gd compiler option forces the __cdecl calling convention. Example In the following example, the compiler is instructed to use C naming and calling conventions for the system function: // Example of the __cdecl keyword _CRTIMP int __cdecl system(const char *); END Microsoft Specific |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 11471
|
se non ricordo male __attribute__ è un estensione di gcc che viene usata per specificare un sacco di cosine carine al compilatore inserendole nel codice. se il compilatore non è compatibile basta una macro e riesci a togliere tutto.
ciao |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Quote:
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Doh, ho appena visto che esiste anche su linux __attribute__((__stdcall__)), e crea la stessa convenzione di chiamata presente su windows.
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Oct 2002
Città: Roma
Messaggi: 1502
|
grazie per le risposte, quindi non fa parte della sintassi standard del c, ma dal punto di vista sintattico sapete dirmi che ruolo ha __attribute__(....)? perche ho bisogno di specificare la grammatica del linguaggio per il parsing...oppure sapete indicarmi un documento che descriva queste estensioni del gcc o meglio la sua grammatica? Grazie e ciao.
__________________
Sun Certified Java Programmer EUCIP Core Level Certified European Certification of Informatics Professionals |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
__attribute__ definisce una direttiva per il compilatore, impostando un dato "attributo" all'oggetto cui si riferisce. Una specie di #pragma, se vuoi.
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:34.



















