preprocessor

Using XSLT as an XML pre-processor

不羁的心 提交于 2019-12-02 02:29:34
This is my first time doing anything with XSLT, or XML really, so please excuse me. I've found XSLT web documentation is really terse. I have an XML file that I want to process to selectively drop content based on an input set of defines. The behavior should be similar to a simple code pre-processor handling ifdef blocks. I've worked out how to do it as below, but some parts such as the "contents" variable didn't seem like the best way to handle this. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" /> <xsl:param name="defines-uri"

Includes revealing with Fortran preprocessor

空扰寡人 提交于 2019-12-01 22:26:31
问题 I would like to understand how the preprocessor inlines includes into the code in Fortran. With C, it's pretty simple: Test.c: #include <stdio.h> int main(void) { return 0; } Then I compile using: gcc -E test.c Then it displays the content generated by the C preprocessor, as expected. Now assume I have this Fortran code: Test.f: program test include "mpif.h" call mpi_init call mpi_finalize end Then I run: gfortran -E -cpp test.f // For some reason I need -cpp when using -E in Fortran But I

Includes revealing with Fortran preprocessor

烈酒焚心 提交于 2019-12-01 21:59:25
I would like to understand how the preprocessor inlines includes into the code in Fortran. With C, it's pretty simple: Test.c: #include <stdio.h> int main(void) { return 0; } Then I compile using: gcc -E test.c Then it displays the content generated by the C preprocessor, as expected. Now assume I have this Fortran code: Test.f: program test include "mpif.h" call mpi_init call mpi_finalize end Then I run: gfortran -E -cpp test.f // For some reason I need -cpp when using -E in Fortran But I won't have the expected result, which is the generated include embedded into the code. Instead, I have

Scala, Maven, and preprocessors

Deadly 提交于 2019-12-01 20:52:06
问题 I know all of the philosophical arguments against preprocessors and macros in Java. I don't agree that just because some may abuse a language feature, it should be excluded for all. I would like to include __FILE__ and __LINE__ macros in my Java and Scala code for efficient logging. Any use of Exception is unacceptable because of runtime performance impacts. Those people who argue that logging can be turned off in "production code" should heed the advise of Brian Kernighan: Removing the error

Disable or enable code by preprocessor

蹲街弑〆低调 提交于 2019-12-01 19:54:55
In C++ I'd write bool positive (int a) { #ifdef DEBUG cout << "Checking the number " << a << "\n"; #endif return a > 0; } In OCaml I could write let positive x = begin printf "Checking the number %d\n" x; x > 0 end But how can I disable the printf statement when not in debug mode? you can use cppo : https://github.com/mjambon/cppo . This is available via opam, and offers C like preprocessor features. Without preprocessing you can simply have a global flag defined as let debug = true and write: if debug then printf ...; This code is removed by ocamlopt if debug is false. That said, it's

How to detect architecture in NASM at compile time to have one source code for both x64 and x86?

 ̄綄美尐妖づ 提交于 2019-12-01 18:22:47
I am looking for some preprocessor functionality in nasm that would allow having one source code for both x86 and x64 architectures. I mean something in the vein of ifdef some_constant. Like C preprocessor uses if it wants to detect say if it's compiled on Windows or Linux. Edit I know about nasm flags. I use them. I just want to have the very same source code and expect preprocessor to handle it correctly based on those flags. I'd use ifdef ... else for stack operations and so one, having the core code same for both architectures. NASM cannot detect the architecture, but you can use the

C Preprocessor Macro equivalent for Python

大憨熊 提交于 2019-12-01 18:18:18
问题 I use to define macros (not just constants) in C like #define loop(i,a,b) for(i=a; i<b; ++i) #define long_f(a,b,c) (a*0.123 + a*b*5.6 - 0.235*c + 7.23*c - 5*a*a + 1.5) Is there a way of doing this in python using a preprocess instead of a function? *By preprocess I mean something that replaces the occurrences of the definition before running the code (actually not the whole code but the rest of the code, because since it's part of the code, I guess it will replace everything during runtime).

“Design Mode” preprocessor directive

六眼飞鱼酱① 提交于 2019-12-01 14:30:58
问题 I have a problem on displaying a component in Designer. I identified the "bad" code that the designer does not like. Now, the problem is that I can't "comment" it for design time only using preprocessor directives. Now, I tried (for VB.NET) the following #If Not Debug Then Private Sub myWpfComponent_ItsEvent(sender, args) Handles myWpfComponent.ItsEvent ... #End If this... worked, and now it is displayed without problems in the designer. The problem now that I am afraid do not be able to

How expensive it is for the compiler to process an include-guarded header?

时光怂恿深爱的人放手 提交于 2019-12-01 12:06:34
问题 To speed up the compilation of a large source file does it make more sense to prune back the sheer number of headers used in a translation unit, or does the cost of compiling code far outweigh the time it takes to process-out an include-guarded header? If the latter is true an engineering effort would be better spent creating more, lightweight headers instead of less. So how long does it take for a modern compiler to handle a header that is effectively include-guarded out? At what point would

Why preprocessor behaves differently in #include directive then in [Files] section Inno Setup script

北城以北 提交于 2019-12-01 12:05:05
Was trying to understand the difference between a syntax that would include another script file and a source file in Inno Setup script while using macros to search and find files. I have tried to use FindFolder function from Find a directory using wildcard in Inno Setup : #define FindFolder(Path) \ Local[0] = FindFirst(Path, faDirectory), \ Local[0] ? AddBackslash(ExtractFileDir(Path)) + FindGetFileName(Local[0]) : Path Like this: #include "{#FindFolder('..\..\..\packages\ScriptPreRequisites*')}\DotNetDependencies.iss" Within # you are in the "realm" of Inno Setup preprocessor . There are two