compile error - help please 
Author Message
 compile error - help please

I was trying to take a string ( Pri_rec w/ value eg. '1.00')  make the string ( pri_rec)
into a real (pri_real)  then * it by 1.20, and then format it (:6:2), then put it back into
the string (pri_rec) again .

I'm sure there are more compact ways of doing it, but please see the code
snip below - way am I getting this compiler error? Any help appreciated.
Thanks.

....
val(pri_rec, pri_real, code);
pri_real := pri_real * 1.20;
str ( pri_real :6:2, pri_rec );
.....
AMZPVT2.PAS(94): Error 89: ")" expected.
            str ( pri_real :6:2, pri_rec );
                           ^



Sat, 22 Nov 2003 08:33:17 GMT  
 compile error - help please

Quote:

>val(pri_rec, pri_real, code);
>pri_real := pri_real * 1.20;
>str ( pri_real :6:2, pri_rec );
>.....
>AMZPVT2.PAS(94): Error 89: ")" expected.
>            str ( pri_real :6:2, pri_rec );

What you have should work. Is it typed exactly as you have it
here?  


Sat, 22 Nov 2003 09:52:38 GMT  
 compile error - help please
I figured it out, it seems like a bug to me.
I had  statements:

 type
   str  = string;
.....
var
   name1 : str;
......
begin
.....
val(pri_rec, pri_real, code);
pri_real := pri_real * 1.20;
str ( pri_real :6:2, pri_rec );
.......
end.

I changed str (the "str" in:  str  = string;) to str1, because I had the
idea that having str as an "alias" for the string type and using the
str library function in the same program might be the cause.
After i did that it compiled. Try it. Why didn't TP 7.01 know
the different context of the use of str?

Lee G.

Quote:


> >val(pri_rec, pri_real, code);
> >pri_real := pri_real * 1.20;
> >str ( pri_real :6:2, pri_rec );
> >.....
> >AMZPVT2.PAS(94): Error 89: ")" expected.
> >            str ( pri_real :6:2, pri_rec );

> What you have should work. Is it typed exactly as you have it
> here?



Sat, 22 Nov 2003 11:51:52 GMT  
 compile error - help please

Quote:
> I figured it out, it seems like a bug to me.

Yes, one in your program.

Quote:
> I changed str (the "str" in:  str  = string;) to str1, because I had the
> idea that having str as an "alias" for the string type and using the
> str library function in the same program might be the cause.
> After i did that it compiled. Try it. Why didn't TP 7.01 know
> the different context of the use of str?

Because you are allowed to redefine pretty much everything except
reserved words, and the compiler assumes that when you do, the
later declaration (yours) takes priority. This means, for example,
that if you use Mr. B's snazzy Foo unit, and Mr. B releases a new
version with a new routine called Baz, all your programs using
Baz as a variable don't suddenly break. It also means that if you
want to use a unit but one of its routines isn't very good, you
can replace it with your own version. And so on.

The price of this is that if you want to use something, you can't
declare that its name should mean something else. I don't see this
as a particularly onerous restriction.

--
The Scarlet Manuka



Sat, 22 Nov 2003 17:28:28 GMT  
 compile error - help please

Quote:

>  type
>    str  = string;

Given the above definition then Turbo Pascal is trying to parse:

Quote:
> str ( pri_real :6:2, pri_rec );

as str(pri_real) which is a cast of pri_real from whatever it's real type
is into a string (i.e. a type str).

--
john R. Latala



Sat, 22 Nov 2003 19:03:45 GMT  
 compile error - help please

Quote:

>I changed str (the "str" in:  str  = string;) to str1, because I had the
>idea that having str as an "alias" for the string type and using the
>str library function in the same program might be the cause.
>After i did that it compiled. Try it. Why didn't TP 7.01 know
>the different context of the use of str?

The compiler cannot read your mind. If you redefine a predefined
identifier, then it works ion the new meaning, not in the old.

You can resolve this by specifying exactly that you want the stir
from system unit by writing: system.str(  ); This is my standard
thing when I see unexpected behavior from an identifier. (When
one has several units same names can become common, unless one
uses such awful names with some letters in front like sfxg_str()

Osmo



Sat, 22 Nov 2003 22:15:09 GMT  
 compile error - help please

Quote:


> > I figured it out, it seems like a bug to me.

> Yes, one in your program.

It's not a bug.

Quote:
> > I changed str (the "str" in:  str  = string;) to str1, because I had the
> > idea that having str as an "alias" for the string type and using the
> > str library function in the same program might be the cause.
> > After i did that it compiled. Try it. Why didn't TP 7.01 know
> > the different context of the use of str?

> Because you are allowed to redefine pretty much everything except
> reserved words, and the compiler assumes that when you do, the
> later declaration (yours) takes priority. This means, for example,
> that if you use Mr. B's snazzy Foo unit, and Mr. B releases a new
> version with a new routine called Baz, all your programs using
> Baz as a variable don't suddenly break. It also means that if you
> want to use a unit but one of its routines isn't very good, you
> can replace it with your own version. And so on.

> The price of this is that if you want to use something, you can't
> declare that its name should mean something else. I don't see this
> as a particularly onerous restriction.

The fact that Pascal (and pretty much every other computer language)
has reserved words is a very grave restriction. It effectively means
that once that language has been around fro a few years, it's no
longer possible to extend it, as introducing new reserved words will
with a very high degree of certainty break existing programs which
have declared variables with tht name of the new reserved word. One of
the languages that has no such restrictions is PL/I, where a statement
like

if if = then then
  do do = to to by by while while(until) until(end);
      ...
  end;
else
  else = if;

is quite happily accepted by the compiler.

Robert



Sun, 23 Nov 2003 00:37:14 GMT  
 compile error - help please

Quote:

>   str  = string;
>.....

>I changed str (the "str" in:  str  = string;)

Yes, that's it.

Quote:
>After i did that it compiled. Try it. Why didn't TP 7.01 know
>the different context of the use of str?

Bcause your own definitions overide the built-in ones.
Generally you should avoid doing that.


Sun, 23 Nov 2003 01:34:02 GMT  
 compile error - help please



Quote:


> > > I figured it out, it seems like a bug to me.
> > Yes, one in your program.
> It's not a bug.

Sounds like one to me: code that had unexpected consequences
because the programmer did not understand the effects of what
he had written, even though those effects were as specified
in the documentation. If not a bug, what would you call it?

Quote:
> The fact that Pascal (and pretty much every other computer language)
> has reserved words is a very grave restriction. It effectively means

But the OP's problem was from precisely the opposite cause.
If str had been a reserved word, he wouldn't have been able
to redeclare it and the compiler would have spotted his
error. The fact that it wasn't a reserved word meant that he
could redeclare it and then forget that he had done so. It
wasn't a case of a program that used to work breaking because
it found "str" suddenly in the library; the programmer told
the compiler that he wanted "str" to mean something different,
but tried to use it with its original meaning as well as the
new one, and didn't bother to specify which he meant.

Quote:
> that once that language has been around fro a few years, it's no
> longer possible to extend it, as introducing new reserved words will
> with a very high degree of certainty break existing programs which
> have declared variables with tht name of the new reserved word. One of

I haven't seen anyone complaining that they can't compile
their old TP programs under TP7 because they use "object"
and "inherited" as variables. Nevertheless, supposing that
this did happen and furthermore that it was enough of a
problem that people couldn't simply rename their variables
and recompile, that doesn't mean the language couldn't be
extended; it just means non-reserved words would need to
be used, which is the way almost all of Borland's extensions
were done.

Yes, sometimes people will already be using these identifiers
in their programs. Well, so what? The compiler will give
their definitions precedence and nothing will break. If
they're expanding their program and it's too much effort
to rename variables they can use the unitname.identifier
syntax to differentiate between the two.

Quote:
> the languages that has no such restrictions is PL/I, where a statement
> like

> if if = then then
>   do do = to to by by while while(until) until(end);
>       ...
>   end;
> else
>   else = if;

> is quite happily accepted by the compiler.

And how readable is this code? Do you think this is a good
thing?

--
The Scarlet Manuka



Sat, 29 Nov 2003 15:36:19 GMT  
 compile error - help please
Is there a compiler directive to give a warning when I redefine a word such as str?
I'd prefer to be warned when I overide a method name like this.
thanks


Quote:






> > > > I figured it out, it seems like a bug to me.
> > > Yes, one in your program.
> > It's not a bug.

> Sounds like one to me: code that had unexpected consequences
> because the programmer did not understand the effects of what
> he had written, even though those effects were as specified
> in the documentation. If not a bug, what would you call it?

> > The fact that Pascal (and pretty much every other computer language)
> > has reserved words is a very grave restriction. It effectively means

> But the OP's problem was from precisely the opposite cause.
> If str had been a reserved word, he wouldn't have been able
> to redeclare it and the compiler would have spotted his
> error. The fact that it wasn't a reserved word meant that he
> could redeclare it and then forget that he had done so. It
> wasn't a case of a program that used to work breaking because
> it found "str" suddenly in the library; the programmer told
> the compiler that he wanted "str" to mean something different,
> but tried to use it with its original meaning as well as the
> new one, and didn't bother to specify which he meant.

> > that once that language has been around fro a few years, it's no
> > longer possible to extend it, as introducing new reserved words will
> > with a very high degree of certainty break existing programs which
> > have declared variables with tht name of the new reserved word. One of

> I haven't seen anyone complaining that they can't compile
> their old TP programs under TP7 because they use "object"
> and "inherited" as variables. Nevertheless, supposing that
> this did happen and furthermore that it was enough of a
> problem that people couldn't simply rename their variables
> and recompile, that doesn't mean the language couldn't be
> extended; it just means non-reserved words would need to
> be used, which is the way almost all of Borland's extensions
> were done.

> Yes, sometimes people will already be using these identifiers
> in their programs. Well, so what? The compiler will give
> their definitions precedence and nothing will break. If
> they're expanding their program and it's too much effort
> to rename variables they can use the unitname.identifier
> syntax to differentiate between the two.

> > the languages that has no such restrictions is PL/I, where a statement
> > like

> > if if = then then
> >   do do = to to by by while while(until) until(end);
> >       ...
> >   end;
> > else
> >   else = if;

> > is quite happily accepted by the compiler.

> And how readable is this code? Do you think this is a good
> thing?

> --
> The Scarlet Manuka



Sat, 06 Dec 2003 11:56:55 GMT  
 compile error - help please


Quote:
> Is there a compiler directive to give a warning when I redefine a word
such as str?
> I'd prefer to be warned when I overide a method name like this.
> thanks

Not that I'm aware of. But there wouldn't have been a problem if you
weren't trying to use the str library function as well, so simply take
care not to assign any variable, type, const etc. names that are names of
library functions you use. It's not really that hard. And if you forget,
you now know the kind of compiler error message to expect...

--
The Scarlet Manuka



Sat, 06 Dec 2003 13:10:26 GMT  
 compile error - help please


Quote:
> Is there a compiler directive to give a warning when I redefine a
word such as str?
> I'd prefer to be warned when I overide a method name like this.
> thanks

No, it's legal. It might rate a hint or warning but shouldn't prevent
compilation. But TurboPascal doesn't do hints and warnings: it
compiles legal code and halts compilation on an error. And if the
compiler were to halt on a redefinition like that, you could break
programs by adding a procedure to a unit used by the program. Even if
you don't change the code that your program actually uses, and the
linker would strip out the added procedure.

But there is a product called Turbo Analyst, by TurboPower Software
which may do it. According to
http://www.turbopower.com/products/Analyst/ there is a "Program
Structure Analyzer - [...] Provides over two dozen reports about your
code, including - [...] Duplicate identifiers report"

Maybe that would be what you are looking for. But that's only what it
says on the website - perhaps someone who has actually used this might
comment?

FP



Sat, 06 Dec 2003 18:43:16 GMT  
 compile error - help please

Quote:



>> Is there a compiler directive to give a warning when I redefine a
> word such as str?
>> I'd prefer to be warned when I overide a method name like this.
>> thanks

> No, it's legal. It might rate a hint or warning but shouldn't prevent
> compilation. But TurboPascal doesn't do hints and warnings: it
> compiles legal code and halts compilation on an error. And if the
> compiler were to halt on a redefinition like that, you could break
> programs by adding a procedure to a unit used by the program. Even if
> you don't change the code that your program actually uses, and the
> linker would strip out the added procedure.

> But there is a product called Turbo Analyst, by TurboPower Software
> which may do it. According to
> http://www.turbopower.com/products/Analyst/ there is a "Program
> Structure Analyzer - [...] Provides over two dozen reports about your
> code, including - [...] Duplicate identifiers report"

> Maybe that would be what you are looking for. But that's only what it
> says on the website - perhaps someone who has actually used this might
> comment?

If your code is clean enough, you could compile with a different BP
compatible compiler and get warnings and hints.


Sat, 06 Dec 2003 19:38:00 GMT  
 compile error - help please


wrote at Tue, 19 Jun 2001 11:38:00 :-

Quote:

>If your code is clean enough, you could compile with a different BP
>compatible compiler and get warnings and hints.

Delphi will do this, and the command-line version can be used.  It will
report many errors per pass; some will be due to language differences
(mainly library).  If one checks a *copy*, one can cut out such parts
and still do a reasonable check on the rest.  Adequate versions of
Delphi are perhaps readily available on magazine cover discs.

--

 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.



Sun, 07 Dec 2003 03:58:43 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. HELP ! HELP PLEASE IN COMPILE TO EXE FILE

2. Help Please on Compile

3. compile error - help!

4. compiling error : HELP !

5. Compile error, Help!

6. Compile error, Help!

7. Please Help - Error 202: Stack overflow error.

8. Please Compile!

9. blobfield error please help!

10. Lib error PLEASE HELP

 

 
Powered by phpBB® Forum Software