I am working with embedded C and sometimes I compile with Eclipse/GCC and sometimes with STMicroelectronics System Workbench. In my code there are a lot of nested macros and I think it would be great to display the expanded macro value as a comment right after the macro (note: only the macros without parameters). So I was thinking of having a post-build .exe-file/script that takes the result from the precompiler and puts it back into the source code as comments after the macros. As an alternative, I could have a pre-build .exe-file/script that executes the pre-compiler (meaning it will be executed twice for each compile) and then modifies the source code. I feel fairly confident about writing the .exe-file/script, but I have no idea how to execute the precompiler "on demand" or how to view the results of it. Could someone please provide some guidelines on how to achieve this? I know pretty much nothing about makefiles, precompilers, compilers, etc, so please feel free to formulate your answers in this thread in the way you would communicate with a beginner programmer.
See Overall Options (Using the GNU Compiler Collection (GCC))[^]. The -E option of gcc allows you to stop the build after running the preprocessor. The out put will be the expanded source. But be aware that this will include the expansions of all input from included headers so may well be quite extensive. If you run a few samples you should be able to see how to get to the source that you are interested in.
I just tried it, but it seems I need to reference the macros in order to get the expanded values. Most of my macros are never referenced in the project I would like to generate the explanatory comments in, they are just defined in a (shared) .h-file.
If they are not used then the preprocessor will ignore them. Macro expansion happens at the reference, not at the definition. You may need to create some dummy file to get the expansions. A better idea would be to write proper documentation comments so they can be seen by anyone looking at the definitions. And I think that may also make them visible through intellisense.
I am creating an application using c# winform to create and mount ISO files like wincdemu. I am able to create the ISO file and mount it like a local drive. I want to mount the image with disc type CD-ROM/DVD-ROM. I am using AttachVirtualDisk() to mount the image.
Is there any API/library support to mount the image with disc type CD-ROM/CD-R/CD-RW/DVD-ROM/DVD-RAM etc. ?
I appreciate any advice.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
So far it's very basic but this is where we have a big problem because it happens that this deserialization, as simple as it is, allocates pointers m_pFont on the same memory areas from one loop to another. With the same archive file, this problem does not necessarily arise depending on whether you are in Debug or in Release, or even differs from one PC to another.
Afterwards, we inevitably have problems even if the pointers are destroyed ...
Any ideas for ensuring that pointers are not allocated on the same memory range?
I'm not sure to understand how the "serialization" works in your exemple.
What is ar ?
ar >> m_pFont
m_pFont is a pointer, so in my opinion, there is no allocation here, only a pointer (ar) affected to another pointer (m_pFont). You probably have one instance of your font ( managed by your code or the library, I don't know ) referenced ( pointed ) by several m_pFont.
You appear to be confusing serialization and deserialization. The first line above ar >> m_pFont; is deserializing from the archive into the m_pFont object. So where is the deserialize code that loads the object from the archive, and what type is m_pFont?
Well your code remains unclear. However, if m_pFont is a pointer, then you are going to have problems unless you also serialize the object that it is pointing at. Deserializing a pointer without the underlying object means that it will be pointing to some random portion of memory.
This point is treated by the MFC CArchive::ReadObject and CArchive::WriteObject methods which are automatically called by the >> or << operator. They are able to detecte or serialize the associated RuntimeClass.
The example code is very close to the actual code and the problem is that sometimes, depending on the computer, because of the operator >> to deserialize the style m_pFont, several m_pFont pointed to the same memory area.
I studied the problem with a minimal grid ... and finally realized that in my application I was not using this m_pFont. I modified my code so that I would no longer use it at all, destroy it and set it to NULL which definitively resolved my problem.
If I don't fully explain the phenomenon, I think it comes from the fact that these m_pFont contained the same data and that the operators << consider the pointer had already been serialized as explained in the TN002: Persistent Object Data Format | Microsoft Docs ... Maybe ...
Other application can print out without problem ? Have tried to print to another printer ? Or, have you tried to run that command on another machine ? You can find more if you do some debugging on your code ...