PageRenderTime 33ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/php4/variables/example.c

#
C | 90 lines | 68 code | 15 blank | 7 comment | 2 complexity | 63b81d0ef0cc66b574470ab758ddcb00 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* File : example.c */
  2. /* I'm a file containing some C global variables */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "example.h"
  6. int ivar = 0;
  7. short svar = 0;
  8. long lvar = 0;
  9. unsigned int uivar = 0;
  10. unsigned short usvar = 0;
  11. unsigned long ulvar = 0;
  12. signed char scvar = 0;
  13. unsigned char ucvar = 0;
  14. char cvar = 0;
  15. float fvar = 0;
  16. double dvar = 0;
  17. char *strvar = 0;
  18. const char *cstrvar = 0;
  19. int *iptrvar = 0;
  20. char name[256] = "Dave";
  21. char path[256] = "/home/beazley";
  22. /* Global variables involving a structure */
  23. Point *ptptr = 0;
  24. Point pt = { 10, 20 };
  25. /* A variable that we will make read-only in the interface */
  26. int status = 1;
  27. /* A debugging function to print out their values */
  28. void print_vars() {
  29. printf("ivar = %d\n", ivar);
  30. printf("svar = %d\n", svar);
  31. printf("lvar = %ld\n", lvar);
  32. printf("uivar = %u\n", uivar);
  33. printf("usvar = %u\n", usvar);
  34. printf("ulvar = %lu\n", ulvar);
  35. printf("scvar = %d\n", scvar);
  36. printf("ucvar = %u\n", ucvar);
  37. printf("fvar = %g\n", fvar);
  38. printf("dvar = %g\n", dvar);
  39. printf("cvar = %c\n", cvar);
  40. printf("strvar = %s\n", strvar ? strvar : "(null)");
  41. printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
  42. printf("iptrvar = %x\n", iptrvar);
  43. printf("name = %s\n", name);
  44. printf("ptptr = %x (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
  45. printf("pt = (%d, %d)\n", pt.x, pt.y);
  46. printf("status = %d\n", status);
  47. }
  48. /* A function to create an integer (to test iptrvar) */
  49. int *new_int(int value) {
  50. int *ip = (int *) malloc(sizeof(int));
  51. *ip = value;
  52. return ip;
  53. }
  54. int value_int(int *value) {
  55. return *value;
  56. }
  57. /* A function to create a point */
  58. Point *new_Point(int x, int y) {
  59. Point *p = (Point *) malloc(sizeof(Point));
  60. p->x = x;
  61. p->y = y;
  62. return p;
  63. }
  64. char * Point_print(Point *p) {
  65. static char buffer[256];
  66. if (p) {
  67. sprintf(buffer,"(%d,%d)", p->x,p->y);
  68. } else {
  69. sprintf(buffer,"null");
  70. }
  71. return buffer;
  72. }
  73. void pt_print() {
  74. printf("(%d, %d)\n", pt.x, pt.y);
  75. }