Re: typedefs and structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



J.A. Magallon writes:

[...]

 > > 
 > > However, if the code is as follows:
 > > 	void foo (void) {
 > > 		int myvar = 0;
 > > 		printf("%d\n", myvar);
 > > 		bar(&myvar);
 > > 		printf("%d\n", myvar);
 > > 	}
 > > If bar is declared in _another_ file as
 > > 	void bar (const int * var);
 > > then I think the compiler can validly cache the value of 'myvar' for the
 > > second printf without re-reading it. Correct/incorrect?
 > > 
 > 
 > Nope. You can't trust bar() not doing something like
 > 
 > bar(const int* local_var)
 > {
 >    ... use local_var as ro...
 >    extern int myvar;
 >    myvar = 7;
 > }
 > 
 > For the compiler to do that, you must tag bar() with attribute(pure).

extern declaration in your version of bar() cannot refer to the
automatic variable myvar in foo().

 > 
 > --
 > J.A. Magallon <jamagallon()able!es>     \               Software is like sex:
 > werewolf!able!es                         \         It's better when it's free
 > Mandriva Linux release 2006.1 (Cooker) for i586
 > Linux 2.6.14-jam1 (gcc 4.0.2 (4.0.2-1mdk for Mandriva Linux release 2006.1))

Nikita.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux