public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter
@ 2010-12-02 13:57 fredrik.hederstierna@securitas-direct.com
  2010-12-02 14:24 ` [Bug c/46766] " schwab@linux-m68k.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fredrik.hederstierna@securitas-direct.com @ 2010-12-02 13:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46766

           Summary: Type 'void' is treated differently if used as return
                    value or as parameter
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: fredrik.hederstierna@securitas-direct.com


It is valid to return a void-function, or cast a variable to void, from a
void-function.

This makes some sense, in particular in C++ since we might have a template, and
we would like to put 'void' as type in this C++ template.

But then maybe it should also be allowed to put 'void' as inparameter to a
void-function, but then compiler warns about too many arguments.

void.c: In function ‘main’:
void.c:16: error: too many arguments to function ‘f1’
void.c:17: error: too many arguments to function ‘f2’

Somehow it would be more 'aligned' to have function-return-values and
function-in-parameters work the same way, so that template-alike-constructions,
or similar pure C macro/preprocessor constructions, could work the same
perhaps?

void f1(void)
{
  return (void)0; //OK
}

void f2(void)
{
  return f1(); //OK
}

int main(void)
{
  f1();        //OK
  f2();        //OK
  f1((void)0); //ERROR
  f2(f1());    //ERROR
  return 0;   
}


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

* [Bug c/46766] Type 'void' is treated differently if used as return value or as parameter
  2010-12-02 13:57 [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter fredrik.hederstierna@securitas-direct.com
@ 2010-12-02 14:24 ` schwab@linux-m68k.org
  2010-12-02 14:42 ` fredrik.hederstierna@securitas-direct.com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2010-12-02 14:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46766

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> 2010-12-02 14:23:59 UTC ---
void f1(void) declares a function that takes no parameters.


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

* [Bug c/46766] Type 'void' is treated differently if used as return value or as parameter
  2010-12-02 13:57 [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter fredrik.hederstierna@securitas-direct.com
  2010-12-02 14:24 ` [Bug c/46766] " schwab@linux-m68k.org
@ 2010-12-02 14:42 ` fredrik.hederstierna@securitas-direct.com
  2010-12-02 15:14 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: fredrik.hederstierna@securitas-direct.com @ 2010-12-02 14:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46766

--- Comment #2 from Fredrik Hederstierna <fredrik.hederstierna@securitas-direct.com> 2010-12-02 14:42:35 UTC ---
Ok, but also f1() declares that it does not return any parameters, still it can
return (void)0;

I'm not saying either is wrong, I just though it should be consistent.

If its ok to _return_ (void) from a function, why is it not ok to have (void)
as _inparameter_ to a function. Where is the logical difference?

/Fredrik


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

* [Bug c/46766] Type 'void' is treated differently if used as return value or as parameter
  2010-12-02 13:57 [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter fredrik.hederstierna@securitas-direct.com
  2010-12-02 14:24 ` [Bug c/46766] " schwab@linux-m68k.org
  2010-12-02 14:42 ` fredrik.hederstierna@securitas-direct.com
@ 2010-12-02 15:14 ` redi at gcc dot gnu.org
  2010-12-02 15:55 ` fredrik.hederstierna@securitas-direct.com
  2010-12-02 17:10 ` schwab@linux-m68k.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2010-12-02 15:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46766

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-12-02 15:14:14 UTC ---
(In reply to comment #0)
> 
> void f1(void)
> {
>   return (void)0; //OK

This is valid in C++ but allowing it in C is a GCC extension.


> void f2(void)
> {
>   return f1(); //OK

This is valid in C++ but allowing it in C is a GCC extension.


>   f1((void)0); //ERROR
>   f2(f1());    //ERROR

This is repulsive.

I don't see this as "more aligned" with the examples above, I see it as more
aligned with:

int i = (int) f1();   // EURGH

Or consider the following, how many arguments are given to f3?

   void f3(int);
   f3((void)0, f1(), f2(), 3);  // EURGH


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

* [Bug c/46766] Type 'void' is treated differently if used as return value or as parameter
  2010-12-02 13:57 [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter fredrik.hederstierna@securitas-direct.com
                   ` (2 preceding siblings ...)
  2010-12-02 15:14 ` redi at gcc dot gnu.org
@ 2010-12-02 15:55 ` fredrik.hederstierna@securitas-direct.com
  2010-12-02 17:10 ` schwab@linux-m68k.org
  4 siblings, 0 replies; 6+ messages in thread
From: fredrik.hederstierna@securitas-direct.com @ 2010-12-02 15:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46766

--- Comment #4 from Fredrik Hederstierna <fredrik.hederstierna@securitas-direct.com> 2010-12-02 15:55:05 UTC ---
Yes, I agree its EURGH.
I guess its not preferred to make C++ template-alike code in C.
I think its worth avoid stuff like:

#ifdef BLAH_BLAH_BLAH
  #define RETURN_TYPE_C_TEMPLATE  void
  #define PARAM_TYPE_C_TEMPLATE   void
  #define PARAM_TYPE_C_TEMPLATE_VARIABLE
#else
  #define RETURN_TYPE_C_TEMPLATE  int
  #define PARAM_TYPE_C_TEMPLATE   int
  #define PARAM_TYPE_C_TEMPLATE_VARIABLE  var
#endif

RETURN_TYPE_C_TEMPLATE func( PARAM_TYPE_C_TEMPLATE 
PARAM_TYPE_C_TEMPLATE_VARIABLE )
{
  return (RETURN_TYPE_C_TEMPLATE) template_func1(
PARAM_TYPE_C_TEMPLATE_VARIABLE );
}

int main(void)
{
  func((PARAM_TYPE_C_TEMPLATE) template_func2());  
  return ERR_EURGH;
}


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

* [Bug c/46766] Type 'void' is treated differently if used as return value or as parameter
  2010-12-02 13:57 [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter fredrik.hederstierna@securitas-direct.com
                   ` (3 preceding siblings ...)
  2010-12-02 15:55 ` fredrik.hederstierna@securitas-direct.com
@ 2010-12-02 17:10 ` schwab@linux-m68k.org
  4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2010-12-02 17:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46766

--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> 2010-12-02 17:10:15 UTC ---
If you want the standard to be changed then this is the wrong place.


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

end of thread, other threads:[~2010-12-02 17:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-02 13:57 [Bug c/46766] New: Type 'void' is treated differently if used as return value or as parameter fredrik.hederstierna@securitas-direct.com
2010-12-02 14:24 ` [Bug c/46766] " schwab@linux-m68k.org
2010-12-02 14:42 ` fredrik.hederstierna@securitas-direct.com
2010-12-02 15:14 ` redi at gcc dot gnu.org
2010-12-02 15:55 ` fredrik.hederstierna@securitas-direct.com
2010-12-02 17:10 ` schwab@linux-m68k.org

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).