public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Is this a bug in gcc??
@ 2004-12-01 15:09 Martin York
  0 siblings, 0 replies; 7+ messages in thread
From: Martin York @ 2004-12-01 15:09 UTC (permalink / raw)
  To: gcc-help

 Name lastlong wrote:
> Hi,
> 
> I am expecting a error (redefinition of "a") from following piece of 
> code. But gcc (3.4.2) doesnot give any error.
> /////////////////
> int a;
> char b;
> int a;

Just to expand on what has already been said.
gcc/g++ behave as required by the standard. But to make sure we compare
apples to apples.

If you add the above to the file: test.c

gcc -c test.c   # Works Fine     (as expected)
g++ -c test.c   # Outputs errors (as expected)

Note that gcc is a C compiler (or should I say invokes the underlying C
Compiler by default) while g++ is a C++ compiler. NB If you name the
file test.cpp the content is C++ and the C++ compiler will be invoked no
matter how 'Gcc' is invoked (unless you explicitly override the
defaults).


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Assembly optimizations
@ 2004-12-01  9:21 Nathan Sidwell
  2004-12-01  9:39 ` Is this a bug in gcc?? Name lastlong
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Sidwell @ 2004-12-01  9:21 UTC (permalink / raw)
  To: Klaus Winter; +Cc: gcc-help

Klaus Winter wrote:
> Hi all,
> 
> I compiled the following code with gcc-3.3.1. Once without
> optimization and one time with optimization -O. With optimization the
> Decrement function takes a LOT longer than before whereas the
> Increment function stays constant. I haven't found anything in the
> manpage about it ... Any help is appreciated.
> 
> cheers,
> Klaus
> 
> #include <stdio.h>
> #include <time.h>
> #include <sys/time.h>
> 
> int g_Lock_Mini = 0;
> 
> inline int Increment( int* count)
> {
> 	__asm__ __volatile__( "movl $1, %%eax\n\t" 
> 			      "lock; xaddl %%eax, (%%ecx)\n\t"
> 			      "incl %%eax\n\t" : : "c" (count) );
> }
> inline int Decrement( int * count)
> {
> 	__asm__ __volatile__( "lock; decl (%%ecx)\n\t"
> 				  "movl (%%ecx), %%eax\n\t" : : "c" (count));
> }
these asms are broken. I think you want something like

asm volatile("lock;decl (%1)\n\tmovl (%1),%0" : "=r" (result) : "r" (count) : "memory")

gcc does not otherwise know what registers are used by the asm.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

end of thread, other threads:[~2004-12-01 15:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-01 15:09 Is this a bug in gcc?? Martin York
  -- strict thread matches above, loose matches on Subject: below --
2004-12-01  9:21 Assembly optimizations Nathan Sidwell
2004-12-01  9:39 ` Is this a bug in gcc?? Name lastlong
2004-12-01 11:03   ` Nathan Sidwell
2004-12-01 11:55     ` Name lastlong
2004-12-01 13:30       ` Eljay Love-Jensen
2004-12-01 13:35         ` Name lastlong
2004-12-01 13:39       ` Nathan Sidwell

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