comp.lang.ada
 help / color / mirror / Atom feed
* Conditional types?
@ 2002-11-10 20:34 Caffeine Junky
  2002-11-10 21:35 ` tmoran
  0 siblings, 1 reply; 9+ messages in thread
From: Caffeine Junky @ 2002-11-10 20:34 UTC (permalink / raw)


I've been trying to figure out if theres a way in Ada(or any other
language for that matter) to test if data is of a certain type without
going into low level bit fiddling and Assembler instructions.

i.e. Hypothetical situation...

You're recieving data through a function call or a procedure of some
sort, but the source for some reason does not indicate explicitly what
type of data it is. However, since you do have some limited knowledge of
the system you can safely assume it's passing either a float, an integer,
or an unsigned 32 bit integer. Is there a way do this in Ada ...

procedure get(bar : in undefined) -- Note that this does not return or
						  -- output any data
	if datatype(bar) is unsigned_32 then
		declare
	 	 foo : Unsigned_32 := bar;
		begin
			-- process data here
		end;
	else if datatype(bar) is Integer then
		declare
		  foo : Integer := bar;
		begin
			-- process data here
		end;
	else if datatype(bar) is float then
		declare
		 foo : float := bar;
		begin
			-- process data here
		end;
	end if;

end get;

Any tips?

Caffiene Junky



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Conditional types?
@ 2002-11-10 20:34 Caffeine Junky
  2002-11-10 23:04 ` Dennis Lee Bieber
  2002-11-11 13:30 ` Marin David Condic
  0 siblings, 2 replies; 9+ messages in thread
From: Caffeine Junky @ 2002-11-10 20:34 UTC (permalink / raw)


I've been trying to figure out if theres a way in Ada(or any other
language for that matter) to test if data is of a certain type without
going into low level bit fiddling and Assembler instructions.

i.e. Hypothetical situation...

You're recieving data through a function call or a procedure of some
sort, but the source for some reason does not indicate explicitly what
type of data it is. However, since you do have some limited knowledge of
the system you can safely assume it's passing either a float, an integer,
or an unsigned 32 bit integer. Is there a way do this in Ada ...

procedure get(bar : in undefined) -- Note that this does not return or
						  -- output any data
	if datatype(bar) is unsigned_32 then
		declare
	 	 foo : Unsigned_32 := bar;
		begin
			-- process data here
		end;
	else if datatype(bar) is Integer then
		declare
		  foo : Integer := bar;
		begin
			-- process data here
		end;
	else if datatype(bar) is float then
		declare
		 foo : float := bar;
		begin
			-- process data here
		end;
	end if;

end get;

Any tips?

Caffiene Junky



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

end of thread, other threads:[~2002-11-13  6:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-10 20:34 Conditional types? Caffeine Junky
2002-11-10 21:35 ` tmoran
2002-11-11  4:43   ` Caffeine Junky
  -- strict thread matches above, loose matches on Subject: below --
2002-11-10 20:34 Caffeine Junky
2002-11-10 23:04 ` Dennis Lee Bieber
2002-11-13  6:41   ` AG
2002-11-11 13:30 ` Marin David Condic
2002-11-11 17:30   ` Larry Kilgallen
2002-11-12 12:50     ` Marin David Condic

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