通过引用传递给功能

时间:2019-10-27 10:23:16

标签: c++

我具有以下数据结构;

typedef struct
{
    char   ElementSectionName[33];  
        ElementType_t    type;                  
    int    nbndry;              
    int    start;               
    int    end;         
    ...
        ...
    int    *Elements;       
        int    *Neighbors;  
} ElementConnectivity;

typedef struct
{
    char   zonename[33];        
        ZoneType_t    Zonetype;     
    int    *Size;           
        ElementConnectivity *ElementCon;
        ...
        ...
    ...
        ZoneGeometry *ZGeom;  
} Zone;

typedef struct
{
    char   basename[33];        
        int    Cell_Dimension;  
        ...
        ...
        ... 
    Zone   *CgnsZone;   
} Base;
typedef struct
{
    float  version;         /* [C] CGNS MLL Version */
    int    Number_of_bases;     /* [C] Number of 'Base' nodes under 'Root' Node 
    Base   *CgnsBase;       /* [C] 'Base' Nodes under the 'Root' Node */
} Root;

我声明了以下两个函数;

int global(Base *CgnsBase){
  int i,j,node,k;
  FILE *map;FILE *conn;
  ...
  ...
  ...
  cellmapping(CgnsBase->CgnsZone->ElementCon->Elements)
}

单元格映射的定义如下;

int cellmapping(int *parEle)
{
 printf("cellmapping.cpp\n");
 printf("Check_point_1\n");
 ...
 ...
 printf(*(parEle+i));
}

在主要功能中,我已完成以下操作;

int main()
 global(CgnsRoot.CgnsBase);
}

我期望获得Elements数组的第一个元素,因为该数组中有一些元素,并且已经作为指针传递了,但是我得到的是垃圾值。为什么会这样呢?我在哪里做错了。

1 个答案:

答案 0 :(得分:0)

CgnsRoot在哪里?
我认为是根..
尝试将typedef更改为简单的stutt标签

struct ElementConnectivity
{
    char   ElementSectionName[33];  
        ElementType_t    type;                  
    int    nbndry;              
    int    start;               
    int    end;         
    ...
        ...
    int    *Elements;       
        int    *Neighbors;  
};

struct Zone
{
    char   zonename[33];        
        ZoneType_t    Zonetype;     
    int    *Size;           
        ElementConnectivity *ElementCon;
        ...
        ...
    ...
        ZoneGeometry *ZGeom;  
};

struct Base
{
    char   basename[33];        
        int    Cell_Dimension;  
        ...
        ...
        ... 
    Zone   *CgnsZone;   
}e;
struct Root
{
    float  version;         /* [C] CGNS MLL Version */
    int    Number_of_bases;     /* [C] Number of 'Base' nodes under 'Root' Node 
    Base   *CgnsBase;       /* [C] 'Base' Nodes under the 'Root' Node */
};

int global(Base *CgnsBase){
  int i,j,node,k;
  FILE *map;FILE *conn;
  ...
  ...
  ...
  cellmapping(CgnsBase->CgnsZone->ElementCon->Elements)
}

int main()
 global(CgnsRoot.CgnsBase);
}

我要离开...继续