如何禁用 borland c++ 中的异常处理代码5.5 编译器

发布于 2024-12-11 08:49:23 字数 469 浏览 3 评论 0原文

抱歉我的英语很弱,

我正在使用 borland c++ 5.5 编译器,我喜欢它,但是 有时有一个问题让我担心;我正在写纯c 应用程序没有这样一个 C++“功能”,但我 使用 -P 开关编译以强制“c++ 编译”,因为 如果我在 c 模式下编译,我必须声明“int i” 在 for 循环之前,这是愚蠢的。所以我用c++编译 模式,但我担心自己这会让 编译器放置一些异常处理代码 进入我的应用程序 - 当我查看我的程序时 使用十六进制编辑器我看到很多奇怪的字符串 可能与.exe中的异常处理有关; 当我使用 -x- 切换到我的应用程序时,它会带来 没有效果。我什至可以提供我的 progs exe 的链接

dl.dropbox.com/u/42887985/unpack%20aeroplane.zip

如何确保没有异常处理 (并且 exe 中没有任何其他不必要的东西,因为 我更喜欢保持它很小)里面有吗?

非常感谢这个问题的答案,这很重要 对我来说,冷杉

Sorry for my weak english

I'm using borland c++ 5.5 compiler and i like it but
one question worries me sometimes; I am writing pure c
applications with not such one c++ 'feature', but i
compile with -P switch to force 'c++ compile' because
if I compile in c-mode I have to declare "int i"
before for loop and it is stupid. So I compile in c++
mode but I am worrying myself that that it makes
compiler to put some exception handling code
into my applications - when i look into my prog
with hex editor i see a lot of strange strings
possibly related to exception handling in .exe;
when i use -x- switch to my application it brings
no effect. I can even give a link to my progs exe

dl.dropbox.com/u/42887985/unpack%20aeroplane.zip

How can I make sure that no exception handling
(and no any other unnecessary stuff in exe becouse
i prefer to keep it tiny) is present inside?

wery much tnx for answer to that, it is important
for me, fir

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最好是你 2024-12-18 08:49:23

如果不支持作为标准一部分的异常,就不可能有 C++。我不能说它是否对您的可执行文件有很大影响。

如果我是你,我会得到一个更现代的 C 编译器。在 Windows 上你应该尝试 mingw。使用 C99,您可以在任何您喜欢的地方声明变量。 Borland 编译器很古老。

You can't have C++ without support for exceptions which is part of the standard. Whether or not it has much impact on you executable I cannot say.

I'd get a more modern C compiler if I were you. On Windows you should try mingw. With C99 you can declare variables wherever you like. That Borland compiler is ancient.

花开雨落又逢春i 2024-12-18 08:49:23

正如所注意到的,您不能从 C++ 库中排除异常处理。但还有一些其他编译器选项和其他技巧,可以帮助您减少代码大小

  1. 运行时类型识别或 RTTI,它用于 C++ 事物,例如 typeiddynamic_cast< /code> 如果您不使用任何 C++ 可能性,您可以安全地关闭此选项(在循环内定义变量并不重要:-)),这可能会稍微减少您的可执行文件大小。 RTTI 选项默认启用,您可以使用 -RT- 开关切换它。
  2. 代码优化 - 如果您使用聚合 -O2 开关,则启用所有优化,程序将被编译为尽可能最快,但不是最小。您应该使用单独的开关来进行不同的优化。使用 -Ov(归纳变量)和 -Og(优化公共子表达式)优化开关,这可以减少代码大小。不要使用 -Oi 开关(内联内部函数),这会增加代码大小
  3. BCC 5.5 默认使用 80386 指令集(-3 开关)进行编译。您可以选择 Pentium Pro 指令集(-6 开关),这可以减少代码大小。 MMX 指令集也与此选项一起使用 - 它提高了速度,同时减小了大小(抱歉石器时代编译器中没有 SSE 指令;-))
  4. 使用 Pascal 函数调用约定。这样的函数比使用 C 调用约定的函数更快、更小。一个缺点 - 您不能将 c 风格的变量参数列表与此约定一起使用。您可以通过在函数定义中使用 __pascal 关键字或向编译器提供 -p 开关来在源文件中启用此约定

As it was noticed, you can't exclude exception handling from C++ library. But there are also some other compiler options and other tricks, which could help you to reduce code size

  1. Run-Time Type Identification or RTTI, which is used in for C++ things like typeid and dynamic_cast You can safely turn of this option if you don't use any of C++ possibilities, (defining variables inside of loops doensn't matter :-)), this could slightly reduce your executable size. RTTI Option is enabled by default and you can switch it of using -RT- switch
  2. Code optimizations - if you use aggregate -O2 switch, then all optimizations are enabled, program will be compiled to be fastest as possible, but not smallest. Your should use separate switches for different optimizations. Use -Ov (Induction variables) and -Og (Optimize common subexpressions) optimization switches, which could reduce code size. Don't use -Oi switch (Inline intrinsic functions) which will increase code size
  3. BCC 5.5 compiles default using 80386 instructions set (-3 switch). You can select Pentium Pro instructions set (-6 switch) which can reduce code size. MMX instructions set is also used with this options - it increases speed and also, decreases size (sorry no SSE instructions in stone age compiler ;-))
  4. Use Pascal calling convention for functions. Such function will be little faster and smaller then ones using C calling convention. One disadvantage - you can't use c-style variable arguments list with this convention. You can enable this convention in your source files by using __pascal keyword in function definition or by providing -p switch to compiler
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文