Prasad Dabak wrote:
> I am facing some serious problems in my C# application probably due to
> compiler/JIT optimization. Let is give an hypothetical example that
> demonstrates the problem I am running into
> class class2 {
> static string x=class1.func("testparam");
> Now, class1.func() function is getting called only once. Although it
> is passed same parameter the return value of the function may differ
> depending upon some external factors.
>
> I want to ensure, that, class1.func() is always called and not
> optimized at all.
>
> Is there any way to tell compiler/JIT not to do any optmization for
> call to class1.func at all. I know that removing static for varible
> class2.x solves this problem. However, I don't want to do that, as,
> there are too many places II would need to do that in my application.
This has nothing to do with the jitter. The compiler is doing exactly
what you told it to do; the defined semantics of an initialized static
are that it will be initialized once, before it's first read.
If you want class1.func called every time you call class2.func, you'll
have to make x an instance variable, or explicitly reset it within
every call to class2.func.
--
programmer, author
http://www.midnightbeach.com
and father
http://www.midnightbeach.com/hs