Trying to compile a function with pointer to structure as return value with gcc

Click For Summary
SUMMARY

The discussion centers on a compilation error encountered in GCC when attempting to define a function that returns a pointer to a structure. The error message "error: two or more data types in declaration specifiers" arises due to the absence of a semicolon after the structure declaration. To resolve this issue, users are advised to include a semicolon following the struct definition and consider using typedef to simplify the function declaration.

PREREQUISITES
  • Understanding of C programming language syntax
  • Familiarity with GCC (GNU Compiler Collection) version used for compilation
  • Knowledge of struct and pointer concepts in C
  • Experience with typedef in C programming
NEXT STEPS
  • Learn about proper struct declaration syntax in C
  • Research GCC error messages and their meanings
  • Explore the use of typedef for simplifying type declarations in C
  • Practice writing functions that return pointers to structures
USEFUL FOR

C programmers, software developers, and students learning about pointers and structures in C, particularly those encountering compilation errors in GCC.

Werg22
Messages
1,431
Reaction score
1
I get an error with gcc "error: two or more data types in declaration specifiers" when trying to compile something of the form:

struct tag *function (...) { ...}

Apparently it won't let me create functions with return values pointers to structures. I know that it's perfectly valid code, so I don't know why it's not letting me do this. Any help on this would be appreciated.

edit:

The problem seem to have been that I didn't put semi-colons after the structure declarations. The prof mislead me into error.
 
Last edited:
Technology news on Phys.org
Yes, you would need a semicolon after the struct definition statement.
It would also help if you could post an abridged code the demonstrates the problem, and the associated error codes.
Try typedef before your structure definition, so you can declare directly
tag *function(...){...}
just like any other type, if that solves your problem.
 
I needed to implement it by using tags rather than typedef. But thanks for the answer anyways.
 

Similar threads

Replies
12
Views
2K
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 16 ·
Replies
16
Views
6K
  • · Replies 27 ·
Replies
27
Views
6K
  • · Replies 17 ·
Replies
17
Views
4K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K