Read Structure From C header file

This function can create a Matlab structure that match a structure from C header file (.h file)

이 제출물을 팔로우합니다

This function reads a structure from a C header file and convert it to Matlab structure.

[MatlabStruct] = Read_C_Struct_From_header(h_FileName);
[MatlabStruct] = Read_C_Struct_From_header(h_FileName, OutStructName);

h_FileName - The name of the h file (e.g. LogStruct.h)
OutStructName - The name of the structure that will be extructed from the header file. If the name doesn't exist in the file or wasn't input by the user, the last structure in the file will be output

The function also supports nested structures.
The struct can be defined by either 'typedef' or 'struct', but doesn't support mix definitions.
for example:

typedef struct {
unsigned long long Var1;
char Var2;
float Var3[8];
} my_struct;

Or:

struct my_struct {
unsigned long long Var1;
char Var2;
float Var3[8];
};

The function is currently limit to the following data types:
[double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64]
['char', 'short', 'long', 'int', 'long long', 'float', 'double', 'unsigned char', 'unsigned short', 'unsigned long', 'unsigned int', 'unsigned long long']

--------------------------

This function is very useful when trying o read a binary file that was created by C\C++ code. It can be used to to create a structue for the 'cstruct' function:
AJ Johnson (2020). cstruct (https://www.mathworks.com/matlabcentral/fileexchange/4048-cstruct), MATLAB Central File Exchange. Retrieved April 26, 2020.

인용 양식

Lior Alpert (2026). Read Structure From C header file (https://kr.mathworks.com/matlabcentral/fileexchange/75210-read-structure-from-c-header-file), MATLAB Central File Exchange. 검색 날짜: .

일반 정보

MATLAB 릴리스 호환 정보

  • R2016b 이상 릴리스와 호환

플랫폼 호환성

  • Windows
  • macOS
  • Linux
버전 퍼블리시됨 릴리스 정보 Action
1.0.2

Small fix that prevent potential error with some comments in the C header

1.0.1

1. I have added support in 'bool' type
2. Add an example

1.0.0