home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / database / informix / 2477 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  2.9 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!wupost!emory!emory!not-for-mail
  2. From: obelix.informix.com!johnl@emory.mathcs.emory.edu (Jonathan Leffler)
  3. Newsgroups: comp.databases.informix
  4. Subject: Re:  Sharing structs between ESQL and 'C'
  5. Date: 19 Nov 1992 18:08:09 -0500
  6. Organization: Mailing List Gateway
  7. Lines: 82
  8. Sender: walt@mathcs.emory.edu
  9. Distribution: world
  10. Message-ID: <1eh6opINNskg@emory.mathcs.emory.edu>
  11. Reply-To: obelix.informix.com!johnl@emory.mathcs.emory.edu (Jonathan Leffler)
  12. NNTP-Posting-Host: emory.mathcs.emory.edu
  13. X-Informix-List-ID: <list.1626>
  14.  
  15.  
  16. }From: uunet!gauss.rutgers.edu!manmetha (Rajesh Malhotra)
  17. }Subject: Sharing structs between ESQL and 'C'
  18. }Date: 18 Nov 92 19:57:51 GMT
  19. }X-Informix-List-Id: <news.2157>
  20. }
  21. }Fellow Informixers,
  22. }
  23. }    Is there a way to share structure definitions between 'C' and
  24. }the ESQL definitions?
  25. }i.e. Say I have an ESQL definition of the type
  26. }
  27. }    $typedef struct {
  28. }        char var1;
  29. }        int  var2
  30. }    } SQLstruct;
  31. }
  32. }and I also need a 'C' struct
  33. }
  34. }    typedef struct {
  35. }        char var1;
  36. }        int  var2;
  37. }    } Cstruct;
  38. }
  39. }Must I have two definitions.  Is there a workaround that would help me get
  40. }by with a single declaration?
  41.  
  42. This almost comes into the FAQ category, and I've had two previous goes at
  43. answering it.  One of them is elegant and simple; t'other (the more recent,
  44. I regret to say), was horrible and kludgy.  So, I enclose the whole elegant
  45. solution, and the header of the grotesque solution.  I can't think why I
  46. couldn't remember in October what I'd said in September...
  47.  
  48. Yours,
  49. Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>
  50.  
  51. Elegant solution posted in September:
  52. }Date: Thu Sep 17 12:12:40 1992
  53. }From: johnl (Jonathan Leffler)
  54. }Subject: Re:  Declaring Host Variables with STRUCT
  55. }
  56. }>From: uunet!mprgate.mpr.ca!sandie (Bert Sandie)
  57. }>Subject: Declaring Host Variables with STRUCT
  58. }>Date: 16 Sep 92 19:38:52 GMT
  59. }>X-Informix-List-Id: <news.1818>
  60. }>
  61. }> ...
  62. }>
  63. }>The reason I want to use the first method is that I have existing
  64. }>structures which have many embedded STRUCT and I do not want to
  65. }>have to redeclare these in ESQL/C for a second time.
  66. }
  67. }Ah, Easy, I thought.  No, better check it.  Checked it, and it didn't
  68. }work, mainly because I was using a 4.00 ESQL compiler in which temp is
  69. }a reserved word.  When tested on a machine with 5.00, it worked OK.
  70. }
  71. }This works under 5.00 (and probably 4.10, but I haven't proved that!).
  72. }
  73. }File temp.h:
  74. }struct temp
  75. }{
  76. }  char t_l[15];
  77. }  char t_f[15];
  78. }};
  79. }
  80. }File temp.ec:
  81. }EXEC SQL BEGIN DECLARE SECTION
  82. }$include "temp.h";
  83. }struct temp      temp1;
  84. }EXEC SQL END DECLARE SECTION
  85.  
  86. Comment: it would be neater to use this:
  87. EXEC SQL INCLUDE "temp.h";
  88.  
  89. Header from grotesque solution posted in October:
  90. }Date: Wed, 28 Oct 92 21:21:46 GMT
  91. }From: uunet!obelix.informix.com!johnl (Jonathan Leffler)
  92. }Subject: Re: Definition techniques using ESQL-C
  93. }X-Informix-List-Id: <list.1560>
  94. }
  95. }I'd be the last to claim it was elegant, but the solution in the
  96. }shell archive seems to work
  97.