簡體   English   中英

試圖在 z/OS HLASM 和 XL C/C++ metal C 編譯器之間制作“雙語宏”

[英]Trying to make “bilingual macros” between z/OS HLASM and XL C/C++ metal C compiler

我試圖弄清楚如何在單個數據集/文件中包含相同 DSECT/struct 的 HLASM 和 Metal C 定義。

在嘗試此操作之前,我嘗試了我在如何使用#include 進行此工作的我如何 go? 直接放入代碼中時效果很好

所以,我走了另一條路,並想我可以使用#define 將匯編器中的 MACRO 語句更改為 C 編譯器將使用的內容:

  • 將“宏”更改為“#pragma margins(2,72)”
  • 將“MEND”更改為“#pragma nomargins”

     EDIT SSAF.METALC.H(CKKTEST) - 01.01 Columns 00001 00080 Command ===> Scroll ===> CSR ****** ********************************* Top of Data ********************************** 000001 MACRO 000002 */* First line of macro prolog */ 000003 */* Last line of macro prolog */ 000004 *#if 0;=0 // Bypass asm in C 000005 Test DSECT 000006 Test@ DS A 000007 TestINT DS F 000008 TestChar DS C 000009 *#endif 000010 MEND 000011 struct Test { 000012 void *Test@; 000013 int TestInt; 000014 char TestChar; 000015 }; ****** ******************************** Bottom of Data ********************************

我想我可以使用#define 將“MACRO”和“MEND”更改為 C 編譯器想要的東西,首先我嘗試不帶引號:

    EDIT       SSAF.METALC.C(CKLTHING) - 01.01                         Columns 00001 00080 
    Command ===>                                                          Scroll ===> CSR  
    000207 #define MACRO #pragma margins(2,72)                                          
    000208 #define MEND #pragma nomargins                                              
    000209 #include"ckktest.h"                                                             

沒有產生預期的結果:

    |
      207       |#define MACRO #pragma margins(2,72)                                         
      208       |#define MEND #pragma nomargins                                              
      209       |#include"ckktest.h"                                                         
    *=ERROR===========>     CCN3191 The character # is not a valid C source character.       
    *=ERROR===========>     CCN3166 Definition of function pragma requires parentheses.      
    *=ERROR===========>     CCN3191 The character # is not a valid C source character.       
    *=ERROR===========>     CCN3191 The character # is not a valid C source character.       
    *=ERROR===========>     CCN3191 The character # is not a valid C source character.       
    *=ERROR===========>     CCN3276 Syntax error: possible missing '{'?                                            

然后我嘗試用引號將#define 值括起來:

      207       |#define MACRO "#pragma margins(2,72)"                                       
      208       |#define MEND "#pragma nomargins"                                            
      209       |#include"ckktest.h"                                                         
    *=ERROR===========>     CCN3191 The character # is not a valid C source character.       
    *=ERROR===========>     CCN3191 The character # is not a valid C source character.       
      210       |                                                                            

這提供了更少的錯誤消息,但仍然不是我需要的。

注意:我使用的 # 是 EBCDIC 7B。

錯誤消息的描述相當簡潔:

CCN3191 字符 &1 不是有效的 C 源字符。 說明 有關有效字符的信息,請參閱 C/C++ 語言參考。

在消息文本中:

&1 是一個字符。

用戶響應 更改字符。

我參考了 C/C++ 語言參考,但找不到任何說明我不能在#define 中使用“#”的內容。 事實上,關於 # 和 ## 運算符有一些話......

有沒有辦法解決這個問題?

謝謝,斯科特

斯科特,問題是宏不能擴展到預處理指令。 我從 header 猜測您想在一個地方定義結構定義並在 hlasm 和 C/C++ 中使用它。 我建議查看 dsect 工具。 此工具從 hlasm 文件中的 DSECT 聲明生成 C 結構聲明。 這可以提供一個解決方案。

對於ckktest.h,另一個使用宏技巧的選項是這樣的:

StructStart(Test)
MbrAddr(Test@)
MbrInt(TestINT)
MbrByte(TestChar)
StructEnd

在 C 源中,您將包括:

#define StructStart(s) struct s {
#define MbrAddr(m) void *m;
#define MbrInt(m) int m;
#define MbrByte(m) char m;
#define StructEnd };
#include "ckktest.h"

並且在hlasm中趨於相似。

我會看一下 dsect 工具,因為它可以提供從 hlasm 到 C 的映射,並使您能夠維護一個定義。 您的 makefile 將有一個額外的規則來使用 dsect 工具從 hlasm 代碼創建 C header。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM