CDECL Utility

"Jérôme M. Berger" jeberger at free.fr
Mon Dec 31 01:53:20 PST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
> ""J�r�me M. Berger"" <jeberger at free.fr> wrote in message 
> news:fl98b7$pl1$1 at digitalmars.com...
> 
>> void function (int) signal (int, void (function (int));
> 
> This is a function prototype, not a type decl :)  The linker would then 
> expect to find this function somewhere else.
> 
	So is the C version when it doesn't have the "typedef". You would
find this in a header file:

- -------------------->8====================
void (*signal(int, void (*)(int)))(int);
====================8<--------------------

	And this in the associated source file:

- -------------------->8====================
void (*signal(int, void (*)(int)))(int)
{
   // Code for the signal function
}
====================8<--------------------

>> The "alias" version would actually be equivalent to:
>>
>> typedef void (*signal(int, void (*)(int)))(int);
> 
> :|  I'm not entirely sure what that means.
> 
> But the alias makes signal a function type:
> 
> alias void function(int) signal(int, void function(int));
> //signal s; // error, cannot declare s as function type
> signal* s; // OK, s is a function pointer 
> 

	And the equivalent in C:

- -------------------->8====================

typedef void (*signal(int, void (*)(int)))(int);
signal  s1;     // OK: s1 is a function, but it needs to be
                // defined somewhere
signal* s2;     // OK: s2 is a function pointer

...

s2 = s1;        // Now, s2 points to the s1 function

...

void (*s1 (int val, void (*func)(int)))(int) {
   // Code for the s1 function
}

====================8<--------------------

		Jerome
- --
+------------------------- Jerome M. BERGER ---------------------+
|    mailto:jeberger at free.fr      | ICQ:    238062172            |
|    http://jeberger.free.fr/     | Jabber: jeberger at jabber.fr   |
+---------------------------------+------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHeLwQd0kWM4JG3k8RAqokAKCVivJtyS+A0K7A6bMk3Y+zArNiygCfd1a6
/SwkE4tJwgNp3APdM9HlpoU=
=RGqw
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list