Consider the following typedef struct in C:
21:typedef struct source{
22: double  ds;             //ray step
23: double  rx,zx; 开发者_Go百科         //source coords
24: double  rbox1, rbox2;   //the box that limits the range of the rays
25: double  freqx;          //source frequency
26:    int64_t  nThetas;        //number of launching angles
27:    double   theta1, thetaN; //first and last launching angle
28:}source_t;
I get the error:
globals.h:21: error: redefinition of 'struct source' globals.h:28: error: conflicting types for 'source_t' globals.h:28: note: previous declaration of 'source_t' was hereI've tried using other formats for this definition:
struct source{
...
};
typedef struct source source_t;
and
typedef struct{
...
}source_t;
Which both return the same error. Why does this happen? it looks perfectly right to me.
Are you sure you didn't include your header twice (without using #ifndef/#pragma once to avoid that)?
Even if there'd been some mistake in your construct it shouldn't trigger the error "redefinition of '...'" cause it's the very first line?
The most likely cause is that your header file is being included more than once. You need to ensure that if this happens, the typedef is only executed once.
You can do this by wrapping globals.h with:
  #ifndef _globals_h_
  #define _globals_h_
  [...]
  #endif
The errors say a struct source has been defined more than once.
Maybe you included the header file twice?
Just to be on the safe side, be sure that your header gets only included once: put
#ifndef YOUR_HEADER_FILE_NAME
#define YOUR_HEADER_FILE_NAME
at the beginning, and
#endif
at the end of your header file: this will prevent it to be included twice or more by any source file.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论