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

AI Thread Summary
The discussion revolves around an error encountered while compiling C code using GCC, specifically the message "error: two or more data types in declaration specifiers." The issue arose when attempting to define a function that returns a pointer to a structure. The root cause was identified as the omission of semicolons after the structure declarations, which is necessary for proper syntax in C. A suggestion was made to use `typedef` for the structure to simplify declarations, allowing for a more straightforward function definition. However, the original poster resolved the issue by correctly placing semicolons and opted to use tags instead of `typedef`.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top