unitended reference comparision - asp.net

I am getting this warning:
Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
I tried this:
if (Convert.ToString(Session["message"]) == SESSIONTIMEOUT)
or
if (Session["message"].ToString() == SESSIONTIMEOUT)
But I'm still getting the above message.

You should use the Equals method for comparison of Strings, like this:
if (Session["message"].ToString().Equals(SESSIONTIMEOUT))
Generally speaking, the == operator is supposed to perform identity comparison - i.e., verifying that two object references point at the same object. See http://www.andymcm.com/csharpfaq.htm#6.7 for more information.

If you read the compiler warning message carefully, it says how you should solve it:
if ((string)Session["message"] == SESSIONTIMEOUT)
That's what casting the left hand side to string means, and this should be the solution. The reason why the message didn't go away, is that you didn't perform a complete rebuild (recompilation) of your project.
Now if there is any change the left hand side could be an object that's not a string, then use:
if (Session["message"] as string == SESSIONTIMEOUT)
but I guess you will not allow the type of your message to be non-string, so go for my first solution, the one suggested by the warning message.

Related

Weird result for packed number multiplication in an enhancement

I am missing a part to solve my problem.
If I do this operation :
TYPES: ty_p2 TYPE p DECIMALS 2.
DATA: lv_test TYPE ty_p2.
lv_test = '100.00' * '3.00'.
I got this result in a program (specific program) on debugger view :
this is the actual result I expect.
I got this result in a program (enhancement of a standard) on debugger view :
it's not the right result it's as if it were 100*3000 and it doesn't take into account the comma of the right hand operator of the multiplication.
How do you explain this ?
Is there an instruction which applies to the context of the ABAP session and which can modify the interpretation of the packed number during a multiplication? Or do you know where it comes from?
Thanks !
Fixed point arithmetic is not checked for the program.
When you are in change mode in SE38 (or SE80), use MenĂ¼ Goto => Attributes
A popup comes up the checkbox for "Fixed point arithmetic" has to be checked (bottom-right corner of the popup window):
Using F1 Help on the field gives detailed explanation:

How and why is a GNAT.Strings.String_List use clause disallowed? How can you use System.Strings.String_List."&" with infix notation?

Posting for two reasons: (1) I was stuck on unhelpful compiler errors for far too long for such a simple issue and I want the next person to google those messages to come upon my (or other) answers, and (2) I still don't understand disallowing a use clause, so my own answer is really incomplete.
In order to call a program in two places with mostly the same arguments, I want to use the '&' to append to a default list inline:
declare
Exit_Code : constant Integer := GNAT.OS_Lib.Spawn (Program_Name => "gprbuild", Args => (Default_GPR_Arguments & new String'(File_Name_Parameter)));
begin
if Exit_Code /= 0 then
raise Program_Error with "Exit code:" & Exit_Code'Image;
end if;
end;
However, the compiler complains that System.Strings.String_List needs a use clause:
operator for type "System.Strings.String_List" is not directly visible
use clause would make operation legal
But inserting use System.Strings.String_List yields:
"System.Strings.String_List" is not allowed in a use clause
I also got this warning:
warning: "System.Strings" is an internal GNAT unit
warning: use "GNAT.Strings" instead
So I substituted GNAT for System in the with and the use clause and got an extra error in addition to the original 'you need a use clause for System.Strings.String_List' one:
"GNAT.Strings.String_List" is not allowed in a use clause
Why is GNAT.Strings.String_List not allowed in a use clause? Section 8.5 on use clauses doesn't seem to state anything on disallowed packages, so is this a compiler bug? Is it possible to define a new package that cannot have a use clause?
In a use clause of the form
use Name;
Name must be a package name. GNAT.Strings.String_List is a subtype name, not a package name.
There are a number of ways to invoke "&" for String_List. The simplest is to use the full name:
GNAT.Strings."&" (Left, Right)
but presumably you want to be able to use it as an operator in infix notation, Left & Right. Ways to achieve this, in decreasing specificity:
function "&" (Left : GNAT.Strings.String_List; Right : GNAT.Strings.String_List) return GNAT.Strings.String_List renames GNAT.Strings."&"; This makes this specific function directly visible.
use type GNAT.Strings.String_List; This makes all primitive operators of the type directly visible.
use all type GNAT.Strings.String_List; This makes all primitive operations of the type (including non-operator operations) directly visible.
use GNAT.Strings; This makes everything in the package directly visible.
Looks like it is a design decision. And many other packages in System follows this rule. From the s-string.ads (package specification for System.String):
-- Note: this package is in the System hierarchy so that it can be directly
-- be used by other predefined packages. User access to this package is via
-- a renaming of this package in GNAT.String (file g-string.ads).
My guess why this is done in that way: because it isn't in the Ada specification, but extension from GNAT.

LLVM converting a Constant to a Value

I am using custom LLVM pass where if I encounter a store to
where the compiler converts the value to a Constant; e.g. there is an explicit store:
X[gidx] = 10;
Then LLVM will generate this error:
aoc: ../../../Instructions.cpp:1056: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
The inheritance order goes as: Value<-User<-Constant, so this shouldn't be an issue, but it is. Using an a cast on the ConstantInt or ConstantFP has no effect on this error.
So I've tried this bloated solution:
Value *new_value;
if(isa<ConstantInt>(old_value) || isa<ConstantFP>(old_value)){
Instruction *allocInst = builder.CreateAlloca(old_value->getType());
builder.CreateStore(old_value, allocInst);
new_value = builder.CreateLoad(allocResultInst);
}
However this solution creates its own register errors when different type are involved, so I'd like to avoid it.
Does anyone know how to convert a Constant to a Value? It must be a simple issue that I'm not seeing. I'm developing on Ubuntu 12.04, LLVM 3, AMD gpu, OpenCL kernels.
Thanks ahead of time.
EDIT:
The original code that produces the first error listed is simply:
builder.CreateStore(old_value, store_addr);
EDIT2:
This old_value is declared as
Value *old_value = current_instruction->getOperand(0);
So I'm grabbing the value to be stored, in this case "10" from the first code line.
You didn't provide the code that caused this first assertion, but its wording is pretty clear: you are trying to create a store where the value operand and the pointer operand do not agree on their types. It would be useful for the question if you'd provide the code that generated that error.
Your second, so-called "bloated" solution, is the correct way to store old_value into the stack and then load it again. You write:
However this solution creates its own register errors when different type are involved
These "register errors" are the real issue you should be addressing.
In any case, the whole premise of "converting a constant to a value" is flawed - as you have correctly observed, all constants are values. There's no point storing a value into the stack with the sole purpose of loading it again, and indeed the standard LLVM pass "mem2reg" will completely remove such a sequence, replacing all uses of the load with the original value.

Game Maker code error

Now I'm making an endless runner where objects are spawned in front on me randomly.
I was told to make a spawnController and globalController object, so I did. Then this code should be put in the controller under step event
if(tick = 32)
{
tick = 0;
instance_create(room_width,room_height,random(spike,groundBlock));
instance_create(room_width,irandom_range(0,room_height-32));
}
tick += 1;
Is there anything wrong with it because i get an error, which is:
In object spawnController, event Step, action 1 at line 4: Wrong number of arguments to function or script.
instance_create(room_width,irandom_range(0,room_height-32));
The error messages in GM can sometimes be a bit unclear.. But in this case it was pretty clear. It goes about this line. And one of the scripts has too few arguments. Either irandom_range or instance_create you forgot an argument.
irandom_range takes two arguments to make a random number, so that is correct.
instance_create however takes 3 arguments: x,y position and the object from which you wish to create an instance. You're simply missing that argument (and the error tells you that). I think that is a typo as you do it correctly in the creation above.
Manual about instance_create
You have a syntax error here:
instance_create(room_width,irandom_range(0,room_height-32);
There's no closing parentheses or a 3rd argument.
One thing that stood out to me is that you used random instead of choose. Im not sure there is a difference in this situation, but choose allows you to list as many arguments you want.
But the other thing as was pointed out, was that your missing the object you want the 4th life to create. You need to specify what object you want it to make.
instance_create(room_width, irandom_range(0,room_height-32), OBJECT);

How to stop evaluating if the first condion has been passed

I try to evaluate a field in my report but it fails every time :
= IIf(Fields!lectcrs_hrs.IsMissing,
Round(Fields!lectcrs_fee.Value * "1.00", 2),
Round(Fields!lectcrs_fee.Value * Fields!lectcrs_hrs.Value, 2))
in the case of Fields!lectcrs_hrs.IsMissing = true my field is empty and i find that the reason that the second case Round(Fields!lectcrs_fee.Value * Fields!lectcrs_hrs.Value, 2) contains a missing field Fields!lectcrs_hrs .why it checks the second case if it passes the first one !
How to fix this problem ?
The behavior you are looking for is called "short-circuiting" and, unfortunately, the IIf function in Visual Basic does not offer that. The reason being is that IIf() is a ternary function and, as such, all arguments passed into it are evaluated before the function call occurs. A ternary operator (If() in VB 9+), on the other hand, does support conditional evaluation. However, I do not believe that the If() operator can be used as a part of an expression in SSRS.
Given the fact that you are trying to use a field which may or may not exist at run time, I suggest that you create a custom function in your report to handle the proper checking and return values. For reference, take a look at this blog post, which covers the same scenario.

Resources