mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] warnkill trivia 2/2
@ 2002-09-01 14:52 Mikael Pettersson
  2002-09-01 14:56 ` Tomas Szepe
  0 siblings, 1 reply; 13+ messages in thread
From: Mikael Pettersson @ 2002-09-01 14:52 UTC (permalink / raw)
  To: szepe; +Cc: davem, linux-kernel, marcelo

On Sun, 1 Sep 2002 14:39:03 +0200, Tomas Szepe wrote:
>I've been playing a bit with how gcc handles the const qualifiers
>and made an interesting discovery:
>
>Trying to compile
>
>typedef int *p_int;
>void a(const p_int t) { *t = 0; }
>void b(const p_int t) { t = (int *) 0; }
>void c(const int *t) { *t = 0; }
>void d(const int *t) { t = (int *) 0; }
>void e(int const *t) { *t = 0; }
>void f(int const *t) { t = (int *) 0; }
>
>will give 'assignment of read-only location' warnings for
>b(), c() and e(),

In b() t is a const value and you're trying to assign to it,
and in c() and e() t is a pointer-to-const and you're trying
to assign to *t. The compiler catches this. What's the problem?

>i.e. it's impossible to have a constant
>pointer to a non-constant value w/o using a qualified
>typedef.

void g(int * const t) { *t = 0; }

>W/o a typedef, gcc seems unable to tell the difference
>between 'const int *' and 'int const *' altogether.

There is no difference. Read the C spec, or Harbison&Steele
which has had an explanation of 'const' since their '87 2nd Ed.

/Mikael

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH] warnkill trivia 2/2
@ 2002-09-01 10:56 Tomas Szepe
  2002-09-01 10:57 ` David S. Miller
  0 siblings, 1 reply; 13+ messages in thread
From: Tomas Szepe @ 2002-09-01 10:56 UTC (permalink / raw)
  To: marcelo, linux-kernel, davem

2.4.20-pre5: prevent sparc32's atomic_read() from possibly discarding
const qualifiers from pointers passed as its argument.


diff -urN linux-2.4.20-pre5/include/asm-sparc/atomic.h linux-2.4.20-pre5.n/include/asm-sparc/atomic.h
--- linux-2.4.20-pre5/include/asm-sparc/atomic.h	2001-11-08 17:42:19.000000000 +0100
+++ linux-2.4.20-pre5.n/include/asm-sparc/atomic.h	2002-09-01 12:29:36.000000000 +0200
@@ -35,7 +35,7 @@
 
 #define ATOMIC_INIT(i)	{ (i << 8) }
 
-static __inline__ int atomic_read(atomic_t *v)
+static __inline__ int atomic_read(const atomic_t *v)
 {
 	int ret = v->counter;
 

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

end of thread, other threads:[~2002-09-04  8:02 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-01 14:52 [PATCH] warnkill trivia 2/2 Mikael Pettersson
2002-09-01 14:56 ` Tomas Szepe
  -- strict thread matches above, loose matches on Subject: below --
2002-09-01 10:56 Tomas Szepe
2002-09-01 10:57 ` David S. Miller
2002-09-01 11:28   ` Tomas Szepe
2002-09-01 11:25     ` David S. Miller
2002-09-01 11:37       ` Tomas Szepe
2002-09-01 11:35         ` David S. Miller
2002-09-01 12:10           ` Tomas Szepe
2002-09-01 12:16             ` David S. Miller
2002-09-01 12:39               ` Tomas Szepe
2002-09-01 21:57                 ` Bruce Guenter
2002-09-02 22:24     ` Jan Hudec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome