What is the “correct” way to reconcile malloc and new in a mixed C/C++ program?

后端 未结 3 575
生来不讨喜
生来不讨喜 2020-12-16 13:18

I have a mixed C/C++ program. It contains a flex/bison parser which targets C, while the remainder is C++.

Being C, the generated parser and scanner manage their me

3条回答
  •  生来不讨喜
    2020-12-16 14:12

    You don't have to worry about any memory allocated by the generated code of Flex or Bison; they take care of it themselves. For the rest, just use new and delete. (And Flex and Bison are capable of generating C++, of a sort. In general, I've found running the output through a simple script, using sed has been sufficient to make their output truly C++ compatible.)

提交回复
热议问题