home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / oracle / 2779 < prev    next >
Encoding:
Text File  |  1993-01-12  |  4.2 KB  |  140 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!paladin.american.edu!gatech!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!news.funet.fi!funic!nokia.fi!paatero
  2. From: paatero@tele.nokia.fi (Janne Paatero)
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: Pro*C / C++ ??
  5. Message-ID: <PAATERO.93Jan9184847@olorin.tele.nokia.fi>
  6. Date: 9 Jan 93 16:48:47 GMT
  7. References: <145384@lll-winken.LLNL.GOV>
  8. Sender: usenet@noknic.nokia.fi (USENET at noknic)
  9. Organization: Nokia Telecommunications Ltd.
  10. Lines: 126
  11. In-Reply-To: hudek@polaris.llnl.gov's message of 7 Jan 93 22:26:49 GMT
  12. Nntp-Posting-Host: olorin.tele.nokia.fi
  13.  
  14.  
  15. (I'm afraid that I have messed up with my previous posting. If not, my
  16. apologies.)
  17.  
  18.  
  19. Hello Netland and especially David Hudek,
  20.  
  21. In article <145384@lll-winken.LLNL.GOV> David Hudek had questions
  22. about Oracle's Pro*C precompiler and C++.
  23.  
  24. >  Is there any reason why the output of Pro*C couldn't then be
  25. >  run through Sun's C++ compiler and produce good executables? (since the
  26. >  C++ compiler can obviously handle straight C code).
  27.  
  28. The most important experience of mine is: Yes, they can be integrated
  29. and the executables work. (At least in my case --- I've been using
  30. Oracle version 6, Pro*C precompiler version 1.3 and C++ version 2.1
  31. in HP risc boxes, Tandem S2 systems and MIPS risc machines.)
  32.  
  33. >  The only potential problem I can think of at the moment from a programming
  34. >  standpoint is how function declarations are handled...
  35.  
  36. This is true. The workaround that has to be done is to modify the
  37. prototypes of Oracle system calls. As very well known, Pro*C output
  38. has function declarations like
  39.  
  40.     extern void sqlxxx();
  41.  
  42. The trick that changes these to be compliant with C++ is to change the
  43. declaration to varparam (three dots inside parenthesis) and typesafe C
  44. linkage. So the previous declaration should be modified to something
  45. like
  46.  
  47.     #ifdef __cplusplus
  48.     extern "C" {
  49.     #endif /* __cplusplus */
  50.  
  51.     extern void sqlxxx(...);
  52.  
  53.     #ifdef __cplusplus
  54.     }
  55.     #endif /* __cplusplus */
  56.  
  57. The #ifdefs in the previous example are there to make the modified
  58. code also compliant with ANSI standard C.
  59.  
  60. Luckily this workaround task can be easily automated. I'm using the
  61. following shell && nawk script which I hereby release to public,
  62. free of charge, with absolutely no warranty of any kind, under GNU
  63. general public licence.
  64.  
  65. The script takes the precompiled file as argument, locates the Oracle
  66. system call prototypes and makes the modifications described above to
  67. them. The original file is saved with a suffix .old.
  68.  
  69. Hope this helps,
  70.  
  71.     janne
  72.  
  73. /******************************************************************************
  74.  Janne Paatero           * "Maybe a db wheenie in Nokia Telecommunications Oy"
  75.  paatero@tele.nokia.fi   * "but still speaking only for myself."
  76.  paatero@ntc.nokia.com   *
  77. ******************************************************************************/
  78.  
  79. ---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--
  80. #!/bin/sh
  81. #
  82. # A simple shell and nawk script to repair output of Pro*C precompiler of
  83. # Oracle Inc. to make it compliant with C++.
  84. #
  85. # Copyright (C) Janne Paatero, 1992.
  86. # You may use and redistribute this under GNU general public licence.
  87. #
  88.  
  89. if [ $# -ne 1 ]
  90. then
  91.     echo "You should give the name of the file to be repaired."
  92.     exit 1
  93. fi
  94.  
  95. awk 'BEGIN {
  96.  
  97. #    Set up global variables, types and parameters.
  98.  
  99.     first = 1
  100.     last = 0
  101. }
  102.  
  103. function beginToken() {
  104.     printf("/*******************************************************/\n")
  105.     printf("/***          Repaired for C++ by PCCrepair          ***/\n")
  106.     printf("/***          PCCrepair script by J.Paatero          ***/\n")
  107.     printf("/*******************************************************/\n")
  108.         printf("#ifdef __cplusplus\n")
  109.     printf("extern \"C\" {\n")
  110.     printf("#endif /* __cplusplus */\n")
  111. }
  112.  
  113. function endToken() {
  114.         printf("#ifdef __cplusplus\n")
  115.     printf("}\n")
  116.     printf("#endif /* __cplusplus */\n")
  117. }
  118.  
  119. {
  120.     while ($1 == "extern" && $2 == "void" && $3 ~ /^sql/ && $3 ~ /\(\);$/){
  121.       if (first) {
  122.         first = 0
  123.         last = 1
  124.         beginToken()
  125.       }
  126.       sub(/\(\);$/, "(...);")
  127.       print
  128.       getline
  129.     }
  130.     if (last) {
  131.       last = 0
  132.       endToken()
  133.     }
  134.     print
  135. }' $1 >/tmp/PCCrepair.$$
  136. mv -f $1 $1.old
  137. cp /tmp/PCCrepair.$$ $1
  138. rm /tmp/PCCrepair.$$
  139. ---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--
  140.