如何从C ++导入#defined常量到ASPX页面 [英] how to import #defined constant from c++ to aspx page

查看:56
本文介绍了如何从C ++导入#defined常量到ASPX页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是aspx的新手,我想知道是否可以将#define常量从c ++导入到aspx页面.

我问是因为,我正在尝试提高此aspx页面的可读性,该页面使用了像魔术数字这样的常量,并且常量本身是在c ++端定义的.

I am new to aspx and was wondering whether it is possible to import a #define constant from c++ to a aspx page.

I am asking because, I am trying to improve readability on this aspx page which is using the constant like a magic number and the constant itself is defined in c++ side.

推荐答案

没有这是一个预处理程序指令.从技术上讲,此类常量"在已编译的可执行代码中不存在.它不是一个常量,这是在编译之前在源代码中使用它的位置插入的未编译文本.编译后,将其编译为分散在代码或其他任何地方的立即常量,这些常量由编译,优化等的详细信息和选项定义.您没有完整的控制它,并且无法从已加载的可执行映像(如DLL)进行访问.

您可以创建一个静态C ++函数,该函数返回所需的值,导出,然后P/调用该函数.例如:
http://stackoverflow.com/Questions/3146017/how-do-i-share-a-constant-between-c-sharp-and-c-code [#define"来定义值.这种做法主要是过时的,意味着编码风格较差.

—SA
No. This is a preprocessor directive. Technically, such "constant" it does not exist in the compiled executable code. It is not a constant, this is a non-compiled text inserted in the source code in the places where it is used, before compilation. After compilation, it is compiled to immediate constants dispersed in different placed of the code or anything else, which is defined by the details and options of compilation, optimization, etc. You don''t have a full control over it and no access from the loaded executable image like DLL.

You can create a static C++ function returning the value you need, export and then P/Invoke that function. For example:
http://stackoverflow.com/questions/3146017/how-do-i-share-a-constant-between-c-sharp-and-c-code[^].

Besides, I would recommend you to avoid using C++ "#define" for the purpose of the definition of values. This practice is majorly obsolete, means poor coding style.

—SA


这篇关于如何从C ++导入#defined常量到ASPX页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆