Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-03

Problem with CASE statement

12 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

In go32v2 i got a problem with case statement.
With compiler 1.0.10 is this without errors:

const kbDown = $5000;
      kbUp   = $4800;
var ch : char;
begin
  ch:=ReadKey;
  case ord(ch) of
    Hi(kbDown): writeln('kbDown');
    Hi(kbUp)  : writeln('kbUp');
  end;
end.

New FPC compiler 1.9.3 produced error 'duplicate case label'.

With these commands i found that function HI produced 0 for both constants.

  writeln(HexStr(Hi(kbDown),2));
  writeln(HexStr(Hi(kbUp),2));

OK i changed definition of kbDown and kbUp to

const kbDown : word = $5000;
      kbUp   : word = $4800;

and now Hi(kbDown) return $50 etc. but with compilation i got another error 'Constant Expression expected'.

I know what this is but i don't understand why.

Maybe somebody help me ?

This definition 'const kbDown = $5000;' produced word or logint or ... ?

Lubomir Cabla

Reply by email

Matt Emson
to Unknown author
Show quoted text 13 lines
In go32v2 i got a problem with case statement. With compiler 1.0.10 is this without errors: const kbDown = $5000; kbUp = $4800; var ch : char; begin ch:=ReadKey; case ord(ch) of Hi(kbDown): writeln('kbDown'); Hi(kbUp) : writeln('kbUp'); end; end.

Delphi (5 at least) enforces case items to be constants, ie. fixed at compile time..... this looks to be the thing that's changed in the compiler's default mode. Maybe another mode supports extended case functionality?

Anyway, define a const for $50 and $48 and use them... aren't these values fixed at compile time anyway ?

Reply by email

Unknown author

Thanks.

Yes, you're right but i'm using this constants for backward compatibility with Borland Pascal.

The problem is in declarations of constant:

const xxx = $4400;
         yyy = $11;

SizeOf(xxx) = 2 in FPC 1.0.10
4 in FPC 1.9.x
SizeOf(yyy) = 1 in FPC 1.0.10
4 in FPC 1.9.x

Constants xxx and yyy are ordinal types, but i don't know which count of bytes they got.

Maybe now are all constants defined like longword (dword), but in PDF doc for 1.9.2
i can not find this.

Lubomir Cabla

Earlier message 32 lines
-----Original Message----- From: Matt Emson Sent: Tuesday, March 23, 2004 3:19 PM To: Subject: Re: [fpc-pascal]Problem with CASE statement > In go32v2 i got a problem with case statement. > With compiler 1.0.10 is this without errors: > > const kbDown = $5000; > kbUp = $4800; > var ch : char; > begin > ch:=ReadKey; > case ord(ch) of > Hi(kbDown): writeln('kbDown'); > Hi(kbUp) : writeln('kbUp'); > end; > end. Delphi (5 at least) enforces case items to be constants, ie. fixed at compile time..... this looks to be the thing that's changed in the compiler's default mode. Maybe another mode supports extended case functionality? Anyway, define a const for $50 and $48 and use them... aren't these values fixed at compile time anyway ?

Reply by email

Tomas Hajny
to Unknown author

From:
To:
Subject: RE: [fpc-pascal]Problem with CASE statement Date sent: Wed, 24 Mar 2004 08:01:04 +0100

Show quoted text 18 lines
The problem is in declarations of constant: const xxx = $4400; yyy = $11; SizeOf(xxx) = 2 in FPC 1.0.10 4 in FPC 1.9.x SizeOf(yyy) = 1 in FPC 1.0.10 4 in FPC 1.9.x Constants xxx and yyy are ordinal types, but i don't know which count of bytes they got. Maybe now are all constants defined like longword (dword), but in PDF doc for 1.9.2 i can not find this.

Hi (word (xxx)) should work everywhere if you need to specify the size explicitely. You're right that it should be documented, of course.

Tomas

Show quoted text 21 lines
-----Original Message----- From: Matt Emson Sent: Tuesday, March 23, 2004 3:19 PM To: Subject: Re: [fpc-pascal]Problem with CASE statement > In go32v2 i got a problem with case statement. > With compiler 1.0.10 is this without errors: > > const kbDown = $5000; > kbUp = $4800; > var ch : char; > begin > ch:=ReadKey; > case ord(ch) of > Hi(kbDown): writeln('kbDown'); > Hi(kbUp) : writeln('kbUp'); > end; > end.
Surfujete pres VOLNY? Tak proc jeste nejste ve VOLNY klubu? Nyni exkluzivne pro cleny klubu soutez o skvele ceny. http://klub.volny.cz

Reply by email

Unknown author

Hi,

yes i know this re-typing word(xxx), it is OK.

Second - new FPC v1.9.x for statement

var p:pointer
p:=Ptr(a,b);

shows error "Incompatible types: got "FarPointer" expected "Pointer"".

I found i can declare var p:farpointer;
but i did not found any description for this type of pointer how can i use it.

Lubomir Cabla

Earlier message 36 lines
-----Original Message----- From: Tomas Hajny Sent: Wednesday, March 24, 2004 9:20 AM To: Subject: Re: RE: [fpc-pascal]Problem with CASE statement From: To: Subject: RE: [fpc-pascal]Problem with CASE statement Date sent: Wed, 24 Mar 2004 08:01:04 +0100 > The problem is in declarations of constant: > > const xxx = $4400; > yyy = $11; > > SizeOf(xxx) = 2 in FPC 1.0.10 > 4 in FPC 1.9.x > SizeOf(yyy) = 1 in FPC 1.0.10 > 4 in FPC 1.9.x > > Constants xxx and yyy are ordinal types, but i don't > know which count of > bytes they got. > > Maybe now are all constants defined like longword > (dword), but in PDF doc > for 1.9.2 > i can not find this. Hi (word (xxx)) should work everywhere if you need to specify the size explicitely. You're right that it should be documented, of course. Tomas

Reply by email

Peter Vreman
to Unknown author: Thanks. Yes, you're right but i'm using this constants for backward compatibility with…
Show quoted text 17 lines
Thanks. Yes, you're right but i'm using this constants for backward compatibility with Borland Pascal. The problem is in declarations of constant: const xxx = $4400; yyy = $11; SizeOf(xxx) = 2 in FPC 1.0.10 4 in FPC 1.9.x SizeOf(yyy) = 1 in FPC 1.0.10 4 in FPC 1.9.x Constants xxx and yyy are ordinal types, but i don't know which count of bytes they got.

Fixed

Reply by email

Peter Vreman
to Unknown author: yes i know this re-typing word(xxx), it is OK. Second - new FPC v1.9.x for statement var…
Show quoted text 14 lines
Hi, yes i know this re-typing word(xxx), it is OK. Second - new FPC v1.9.x for statement var p:pointer p:=Ptr(a,b); shows error "Incompatible types: got "FarPointer" expected "Pointer"". I found i can declare var p:farpointer; but i did not found any description for this type of pointer how can i use it.

Farpointer is to support mem[] and ptr(seg,offset)^ to access the real mode memory. The type is incompatible with Pointer so you can't accidently use Move() etc. You need the special functions from go32 to access the real mode memory.

Reply by email

Unknown author

Many thanks for your explanation.

Earlier message 29 lines
-----Original Message----- From: Peter Vreman Sent: Wednesday, March 24, 2004 10:23 AM To: Subject: RE: RE: [fpc-pascal]Problem with CASE statement > Hi, > > yes i know this re-typing word(xxx), it is OK. > > Second - new FPC v1.9.x for statement > > var p:pointer > p:=Ptr(a,b); > > shows error "Incompatible types: got "FarPointer" expected "Pointer"". > > I found i can declare var p:farpointer; > but i did not found any description for this type of pointer > how can i use it. Farpointer is to support mem[] and ptr(seg,offset)^ to access the real mode memory. The type is incompatible with Pointer so you can't accidently use Move() etc. You need the special functions from go32 to access the real mode memory.

Reply by email

Thomas Schatzl
to Unknown author: yes i know this re-typing word(xxx), it is OK. Second - new FPC v1.9.x for statement var…

Hello,

Show quoted text 10 lines
Second - new FPC v1.9.x for statement var p:pointer p:=Ptr(a,b); shows error "Incompatible types: got "FarPointer" expected "Pointer"". I found i can declare var p:farpointer; but i did not found any description for this type of pointer how can i use it.

It seems that the syntax and semantics of this function changed with later FPC-versions to something actually useful... ;-)

A "Farpointer" is a pointer consisting of a 16 bit selector and 32 bit offset, while in BP the Ptr() function expected a 16bit/16bit segment:offset.
This is due to different memory models in 32 bit protected mode of FPC and 16 bit real mode in BP/TP. There is no fully compatible automatic way to handle these problems.

In short, you usually don't ever need the Ptr() - function in FPC because all memory is addressed linearly through a single 32 bit address, just use "p := @avariable" if you want to create a pointer to some memory area. It was sometimes required in BP/TP because of memory segmentation in BP programs.

Otoh if you want to access specific memory areas in the real mode memory area (lower 1MB of memory) you need to do some sort of translation. See the go32 - documentation for further details (there is some information about the farpointer stuff as well iirc) if you just want to port your TP/BP DOS application to the go32v2 target.
For the others such a way of accessing memory will not be allowed by the OS anyway (or is limited) and is impossible to do without lots of application and OS specific code.

Eventually this will give you a farpointer to the DOS memory location you want to access:

uses go32;
var p : farpointer;
// this syntax is just a guess.
p := Ptr(getfs(), a shl 4 + b);

getfs() returns a selector which by default describes the DOS memory area. Note that while constructing a pointer to this area might work in all cases, any NT-based OS might prevent access. At least it will be slow. Don't even consider using this on e.g. *nix systems.

Regards,
Thomas

Reply by email

Vincent Snijders
to David Emerson: I haven't cvs'd in a number of months, and it is no longer working. I have a little…
Show quoted text 19 lines
-----Oorspronkelijk bericht----- Van: [mailto:fpc-pascal- Namens David Emerson Verzonden: maandag 30 augustus 2004 11:09 Aan: Onderwerp: [fpc-pascal]can't cvs Hi there, I haven't cvs'd in a number of months, and it is no longer working. I have a little ms-dos batch file that enters the long command for me, so it's not as if my configuration or command or path has changed. I keep getting this error: CVS.EXE [update aborted]: could not find out home directory Perhaps this is just a fluke of the night, or perhaps something somewhere has changed? I see that the instructions on the web have not changed in a long, long time!

Do you have a HOME environment variable set? It says it can't find your home directory where login information is stored.

Vincent.

Reply by email

David Emerson
to Thomas Schatzl: It seems that the syntax and semantics of this function changed with later FPC-versions…

Hi there,

I haven't cvs'd in a number of months, and it is no longer working. I have a little ms-dos batch file that enters the long command for me, so it's not as if my configuration or command or path has changed. I keep getting this error:

CVS.EXE [update aborted]: could not find out home directory

Perhaps this is just a fluke of the night, or perhaps something somewhere has changed? I see that the instructions on the web have not changed in a long, long time!

if it's relevant...

cvs -d -z 3 update -Pd fpc/compiler fpc/rtl fpc/Makefile fpc/Makefile.fpc

(while I'm on the subject, correct me if I'm wrong... this ought to be the minimum to get the compiler + rtl working, compiling from 1.0.10, right?)

Thanks,
David

Reply by email

Unknown author
to David Emerson
David Emerson wrote 5 lines
Hi there, I haven't cvs'd in a number of months, and it is no longer working. I have a little ms-dos batch file that enters the long command for me, so it's not as if my configuration or command or path has changed. I keep getting this error: CVS.EXE [update aborted]: could not find out home directory

This is a local error. Seems like the HOME environment variable is not set or pointing to a wrong directory ?

Perhaps this is just a fluke of the night, or perhaps something somewhere has changed? I see that the instructions on the web have not changed in a long, long time!

Because they are still correct. Nothing has changed on the server.

Show quoted text 6 lines
if it's relevant... cvs -d -z 3 update -Pd fpc/compiler fpc/rtl fpc/Makefile fpc/Makefile.fpc (while I'm on the subject, correct me if I'm wrong... this ought to be the minimum to get the compiler + rtl working, compiling from 1.0.10, right?)

Yes.

Michael.

Reply by email