public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: prototyping functions returning an enum, before the enum is defined
@ 1998-06-29 20:41 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 1998-06-29 20:41 UTC (permalink / raw)
  To: ghazi, schwab; +Cc: egcs

| "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
|
| |> 	Some config/*/*.c files have extern functions returning an
| |> enum of some sort.  Eg, function_arg_padding() in sparc.c which
| |> returns an `enum direction'.  I'd like to be able to prototype these
| |> in sparc.h, but we don't have the definition of `enum direction' from
| |> expr.h yet.
| |> 
| |> 	Is it legal in both KNR and ANSI C to say:
| |>  > extern enum direction function_arg_padding();
| |> 
| |> before `enum direction' has been defined?
| |> 
| |> 	What about doing:
| |>  > enum direction;
| |>  > extern enum direction function_arg_padding();
|
| Both are wrong.  ANSI C does not have forward declarations of enum types.
| >From the C9x draft (6.5.2.3 Tags):
|
|        [#2] A type specifier of the form
|
|                enum identifier
|
|        without an enumerator list shall only appear after the  type
|        it specifies is completed.
|
| I'm pretty sure that this is unchanged from the current standard.

(the current standard is still the 1989/1990 standard).

What I've been doing is declaring the functions as taking an int instead of an
enum, and returning an int:


	#ifndef RTX_CODE
	struct rtx_def;
	#define Rtx struct rtx_def *
	#else
	#define Rtx rtx
	#endif

	#ifndef TREE_CODE
	union tree_node;
	#define Tree union tree_node *
	#else
	#define Tree tree
	#endif

	extern int foo_operand PROTO((Rtx, int));

	       /* ... */

	int
	foo_operand (op, int_mode)
	     rtx op;
	     int int_mode;
	{
	  enum machine_mode mode = (enum machine_mode)int_mode;
		/* ... */
	}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: prototyping functions returning an enum, before the enum is defined
  1998-06-28 12:37 Kaveh R. Ghazi
@ 1998-06-29  3:22 ` Andreas Schwab
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 1998-06-29  3:22 UTC (permalink / raw)
  To: Kaveh R. Ghazi; +Cc: egcs

"Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:

|> 	Some config/*/*.c files have extern functions returning an
|> enum of some sort.  Eg, function_arg_padding() in sparc.c which
|> returns an `enum direction'.  I'd like to be able to prototype these
|> in sparc.h, but we don't have the definition of `enum direction' from
|> expr.h yet.
|> 
|> 	Is it legal in both KNR and ANSI C to say:
|>  > extern enum direction function_arg_padding();
|> 
|> before `enum direction' has been defined?
|> 
|> 	What about doing:
|>  > enum direction;
|>  > extern enum direction function_arg_padding();

Both are wrong.  ANSI C does not have forward declarations of enum types.
From the C9x draft (6.5.2.3 Tags):

       [#2] A type specifier of the form

               enum identifier

       without an enumerator list shall only appear after the  type
       it specifies is completed.

I'm pretty sure that this is unchanged from the current standard.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
schwab@gnu.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

* prototyping functions returning an enum, before the enum is defined
@ 1998-06-28 12:37 Kaveh R. Ghazi
  1998-06-29  3:22 ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Kaveh R. Ghazi @ 1998-06-28 12:37 UTC (permalink / raw)
  To: egcs

	Some config/*/*.c files have extern functions returning an
enum of some sort.  Eg, function_arg_padding() in sparc.c which
returns an `enum direction'.  I'd like to be able to prototype these
in sparc.h, but we don't have the definition of `enum direction' from
expr.h yet.

	Is it legal in both KNR and ANSI C to say:
 > extern enum direction function_arg_padding();

before `enum direction' has been defined?

	What about doing:
 > enum direction;
 > extern enum direction function_arg_padding();

	I'd like to please hear if either of these would be correct.

		Thanks,
		--Kaveh

PS: This was handled in rs6000.[ch] by making function_arg_padding()
return an int and having that int cast to an `enum direction' in the
proper place.  I'd prefer to not have to use that solution if possible.
--
Kaveh R. Ghazi			Project Manager / Custom Development
ghazi@caip.rutgers.edu		Icon CMT Corp.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-06-29 20:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-29 20:41 prototyping functions returning an enum, before the enum is defined Michael Meissner
  -- strict thread matches above, loose matches on Subject: below --
1998-06-28 12:37 Kaveh R. Ghazi
1998-06-29  3:22 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).