LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-12-2010, 10:03 PM   #1
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 55
error: new types may not be defined in a return type


The first line of this struct:

Code:
struct custom_int {
    typedef int big_int;

    big_int value;
    size_t size;
}
is giving me the error described in the thread title. No, it is not nested in any function of any kind, so how could it be a return type?

The compiler also is giving me a note:

Code:
note: (perhaps a semicolon is missing after the definition of ‘custom_int’)
It is a struct, how could it need a semicolon if it already has a body that defines it? I'm confused here.
 
Old 10-12-2010, 10:40 PM   #2
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 66
I don't think you can have a typedef within the struct itself. And are you really just renaming "int" or do you plan on using it in some other way? Because there are all sorts of types available already.
 
Old 10-12-2010, 10:51 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,241

Rep: Reputation: 194Reputation: 194
Take the typedef outside the structure.
Also, i prefer to put a ';' after the '}'.
 
Old 10-12-2010, 11:13 PM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,368
Blog Entries: 52

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by Kenny_Strawn View Post
It is a struct, how could it need a semicolon if it already has a body that defines it? I'm confused here.
The semicolon should be at the end of the body, eg
Code:
struct custom_int {
...
};
What is happening is that the compiler is assuming that the struct is the return type of the code that follows the declaration of the struct (possibly one of your functions) because the statement was not terminated.

A typedef is quite legitimate inside a class or struct.

Last edited by neonsignal; 10-12-2010 at 11:14 PM.
 
Old 10-13-2010, 01:21 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by Kenny_Strawn View Post
The first line of this struct:

Code:
struct custom_int {
    typedef int big_int;

    big_int value;
    size_t size;
}
is giving me the error described in the thread title. No, it is not nested in any function of any kind, so how could it be a return type?

The compiler also is giving me a note:

Code:
note: (perhaps a semicolon is missing after the definition of ‘custom_int’)
It is a struct, how could it need a semicolon if it already has a body that defines it? I'm confused here.
The compiler told you that your code is not compliant with the C99 standard ( http://www.open-std.org/JTC1/SC22/wg...docs/n1124.pdf ).

So, find in the standard the chapters which describe how 'struct' can be written. I.e. it is an issue directly related to the standard.

And, as we were taught at school, you do not understand definitions, you learn them by heart. I.e. the question about semicolon is irrelevant - you should act according to the standard.
 
  


Reply

Tags
bignum, g++ error, struct


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Conflicting type declarations between sys/types.h and linux/types.h Da Shi Cao Programming 3 09-14-2010 12:55 AM
cifs and 426 Sendfile error: Value too large for defined data type punt Linux - Networking 5 04-10-2008 06:59 AM
PHP return type error bahadur Programming 0 08-11-2006 05:37 AM
Error while compiling kernel 2.4.20-8 (conflicting return type of _exit function) samkraju Red Hat 1 07-01-2006 07:41 AM
Used but not defined as type error ChemicalBurn Programming 2 05-24-2005 09:04 AM


All times are GMT -5. The time now is 10:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration