home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20212 < prev    next >
Encoding:
Text File  |  1993-01-26  |  3.3 KB  |  99 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!mcsun!dxcern!burow
  3. From: burow@dxcern.cern.ch (Burkhard Burow)
  4. Subject: (cast) proposal (WAS: functions as arguments in DEC C)
  5. Message-ID: <1993Jan26.135214.9306@dxcern.cern.ch>
  6. Organization: CERN European Laboratory for Particle Physics
  7. Date: Tue, 26 Jan 1993 13:52:14 GMT
  8. Lines: 89
  9.  
  10.  
  11. In article <1993Jan23.211019.6955@dxcern.cern.ch>,
  12. I asked how one could cast a pointer to a function, say 'void ( *a)()',
  13. to a "generic pointer to a function" which could be passed
  14. as an argument to a function expecting a pointer to a function, 
  15. say 'int  ( *c)()' in the prototype.
  16.  
  17. Note: I don't wish or need to cast pointers to objects to pointers to functions,
  18.       or vice versa.
  19. and
  20.       I wish to benefit as much as possible from function prototyping.
  21.  
  22. CONSTRAINT:
  23. My application doesn't know that 'int  ( *c)()' is expected, it just knows
  24. that a pointer to a function is expected.
  25.  
  26. I thank all those that replied, but unfortunately, my original posting didn't
  27. make the above CONSTRAINT clear enough, so most of the replies told me to do:
  28.  
  29.  (int (*)())a
  30.  
  31. My application can't do '(int (*)())a' because it doesn't know that a pointer
  32. to a function returning int is expected.
  33. It just knows that a pointer to function is expected.
  34.  
  35. In my followup <1993Jan24.094945.7767@dxcern.cern.ch>, I emphasized
  36. the constraint and explained why my application has this constraint.
  37.  
  38. My followup was followed by <C1DCr5.2v1@micrognosis.co.uk>, nreadwin@micrognosis.co.uk (Neil Readwin)
  39. -|>That's why I need a cast for saying:
  40. -|> 'This is a pointer to a function.
  41. -|>  I don't give a flying f*** about the type of argument the function returns.'
  42. -Having spent a little time reading through both the standard and the Rationale
  43. -(especially 3.2.2.3), I do not think that ANSI C provides this. This came as
  44. -something of a surprise to me.
  45.  
  46. RFC: Why doesn't ANSI C provide this?
  47.  
  48. In a similar vein:
  49.  
  50. QQQQuestion: Does C provide a cast, other than (void *) to do the following?
  51.  
  52. #include <stdlib.h>
  53.  
  54. void f(int a[3][5]) { a[0][0] = 1; return; }
  55.  
  56. typedef ?????  CAST;
  57.  
  58. void g(int *b)
  59. {
  60. f( (CAST) b);
  61. }
  62.  
  63. CONSTAINT:
  64. My application, generating the intermediate function g,
  65. knows the type of the array 'b',     in this case 'int',
  66. and the number of dimensions of 'b', in this case 2
  67. but it doesn't know the size of the individual dimensions, here 3 and 5.
  68.  
  69. EMBARRASSMENT:
  70. I must admit that I can't make the cast for 'b' even if I do use the size of
  71. the individual dimensions, though I don't understand why ANSI C wouldn't like
  72. it.
  73. gcc complains 'cast specifies array type' as soon as I have [] inside a cast.
  74. Clarifications/Justifications sought.
  75.  
  76. QQQuestion/PPProposal:
  77. Why doesn't C allow 'incomplete casting' in order to allow one to best match
  78. the prototyping of the arguments of functions?
  79. e.g.
  80. i)   pointer to function >cast> pointer to function returning void or any type:
  81.      ((*)())
  82.  
  83. ii)  pointer to object   >cast> address of 2D array of ints:
  84.      (int [][])
  85.  
  86. iii) pointer             >cast> cast as required by the function prototype
  87.      ()
  88.  
  89. My application needs i) and ii). [iii) might be fun though.]
  90.  
  91. At the moment ANSI C allows only 'perfect casting' or the brute force 'void',
  92. i) and ii) would allow one to cast with as much info. as one has.
  93.  
  94. Thanks again to all those taking an interest in my plight,
  95. especially to those who sent me a reply.
  96.  
  97. burkhard,       burow@vxdesy.cern.ch
  98.