www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/11/20:02:27

Message-Id: <3.0.1.32.20010112084816.006bc314@wingate>
X-Sender: n_abing#ns DOT roxas-online DOT net DOT ph AT wingate
X-Mailer: Windows Eudora Pro Version 3.0.1 (32)
Date: Fri, 12 Jan 2001 08:48:16 +0800
To: djgpp AT delorie DOT com
From: "Nimrod A. Abing" <n_abing AT ns DOT roxas-online DOT net DOT ph>
Subject: Calling C++ functions from C (or using Bison with C++)
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Hello. I've got an interesting problem. I am writing a program using Bison,
Flex, and C++. The problem is this, I have done the parser and lexer using
Bison and Flex respectively. The guts of the program I intend to write
using C++. The lexer part is okay, because Flex can generate a C++ scanner
(albeit an experimental one). The problem is with the Bison generated
parser. I intended to call C++ functions from within the parser
rule-actions until I realized that this would be a problem because the
parser is in C.

Now, I've tried doing it using pointers to functions. It works, but
(heheheh) is there a better way to do this?

[ file test.cc ]
#include <iostream>


void test()
{
  cout << "Haha it works!!!" << endl;
}



void (*test_addr)() = test;
[ --end--]

[ file main.c ]
#include <stdlib.h>



extern void (*test_addr)();



int main(void)
{
  (*test_addr)();
  exit(0);
}
[ --end-- ]

Help please...


nimrod_a_abing
--------------

+========================================+
|  Home page: www.geocities.com/n_abing  |
+========================================+

ICQ: 54665893

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019