1. Signed Hex Values

A proposed change, in documentation form.

Signed Hex Values

By default hexadecimal values are unsigned. Use "#-" to define signed hexadecimal values, eg:

#FFFFFFFF   -- +4294967295 
#-FFFFFFFF  -- -1 
#80070057   -- +2147942487 
#+80070057  -- +2147942487 
#-80070057  -- -2147024809  -- (the desired value for E_INVALIDARG) 
-#80070057  -- -2147942487 

Note that "#-" is a compiler directive, rather than a unary minus as just seen in that last example. You can also code "#+" for alignmnent purposes, which behaves identically to "#". Some more examples:

#00000001   -- +1 
#+00000001  -- also +1 
#-00000001  -- also +1  (!! make sure you understand why this is plus 1 !!) 
-#00000001  -- -1 
#-FF        -- -1 
#-00FF      -- +255 (make sure you properly sign-extend short forms when editing them) 
if offset>=#-80 and offset<=#7F then use_short_form() end if 
if offset>=-128 and offset<=127 then use_short_form() end if -- (same as above) 

The #- directive triggers a compilation error if the following hexadecimal constant is not 2, 4, or 8 characters, or 16 in 64-bit code.

Comments welcome.

Pete

new topic     » topic index » view message » categorize

2. Re: Signed Hex Values

petelomax said...

A proposed change ...

Signed Hex Values

Why is this a good idea? What's the advantage, etc ...

If adopted, following the same logic, we'd also have to allow the following combinations ...

+#-FFFFFFFF  -- -1 
-#-FFFFFFFF  -- +4294967295 
+#+FFFFFFFF  -- +4294967295 
-#+FFFFFFFF  -- -1 
petelomax said...

The #- directive triggers a compilation error if the following hexadecimal constant is not 2, 4, or 8 characters, or 16 in 64-bit code.

Why have this restriction?

And what about binary literals and hex values inside strings?

new topic     » goto parent     » topic index » view message » categorize

3. Re: Signed Hex Values

DerekParnell said...
petelomax said...

A proposed change ...

Signed Hex Values

Why is this a good idea? What's the advantage, etc ...

Things like E_INVALIDARG (and many many friends). I get a negative HRESULT, I know E_INVALIDARG is 0x80070057, but erm, -2147024809? What else might you suggest?

DerekParnell said...

If adopted, following the same logic, we'd also have to allow the following combinations ...

+#-FFFFFFFF  -- -1 
-#-FFFFFFFF  -- +4294967295 
+#+FFFFFFFF  -- +4294967295 
-#+FFFFFFFF  -- -1 

Yes, I had spotted that potential for code obfuscationblink The correct values would be:

+#-FFFFFFFF  -- -1 
-#-FFFFFFFF  -- +1 
+#+FFFFFFFF  -- +4294967295 
-#+FFFFFFFF  -- -4294967295 

which just goes to show it would be quite good for that. I don't really see what the problem with any of that would be though.

petelomax said...

The #- directive triggers a compilation error if the following hexadecimal constant is not 2, 4, or 8 characters, or 16 in 64-bit code.

DerekParnell said...

Why have this restriction?

I did't think it would be sensible for the compiler to effectively decide on a quite arbitrary basis that say bit 23 was the sign bit?

DerekParnell said...

And what about binary literals and hex values inside strings?

I'm not seeing the same kind of comparison requirement there, so no.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Signed Hex Values

It turns out that I misread your initial examples.

I'm now totally confused about what you are trying to suggest. Your examples seem counter-intuitive and would need a lot of explaining to make sure people understood its intent. And that is an alarm bell for me. In fact, I don't understand some of them at all. Sorry.

Can you explain what is the problem that this idea is attempting to solve?

new topic     » goto parent     » topic index » view message » categorize

5. Re: Signed Hex Values

Ah, nevermind. I was doing

  push eax 
  fild dword[esp] 
  add esp,4 
then checking for error using hResult<0 but not having any of the right values to compare against. If instead I

  push dword 0 
  push eax 
  fild qword[esp] 
  add esp,8 
and check for error using and_bits(hResult,#80000000) then (eg) #800704C7 is fine.

Pete

new topic     » goto parent     » topic index » view message » categorize

6. Re: Signed Hex Values

petelomax said...

...checking for error using hResult<0 but not having any of the right values to compare against. If instead I... and check for error using and_bits(hResult,#80000000) then (eg) #800704C7 is fine.

Yes, that's how you're supposed to check for errors. It's what I do in EuCOM:

 
--/topic Errors 
--/func is_error( atom hresult ) 
--/ret Boolean: 1 if error, 0 if not error 
--Typically, an hresult (the standard return value from a COM function call) will  
--be 0 if no error, and non-zero if an error occurs.  However, there are some values that  
--are non-zero that are 'qualified' successes.  Critical errors, as they are called, can  
--be detected by using a mask of #80000000, which is what this funcion does. 
public function is_error( atom hresult ) 
	return and_bits( hresult, #80000000 ) 
end function 

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu