Sign in Join

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

Mailing lists / lazarus / 2010-07

Note: Local variable "$defaultbufpos" not used

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Bernd
procedure analyzeHistory(...a lot of arguments...); stdcall;
var
  i:       LongInt;
  bufpos:  LongInt = 0;
  balance: Double = 0;
  curtime: LongInt;
begin
   [...]

I did a lot of C in the last 6 months and almost no pascal.

I'm not really sure anymore if i am confusing something or what is going on. The above will compile fine, except some little notes

Note: Local variable "$defaultbufpos" not used
Note: Local variable "$defaultbalance" not used

Somewhere I have read (and I could swear I did it already) that this is the syntax to initialize a variable. I just had a session of over an hour and dozens of crashes because bufpos is an index into some complicated array that comes via the argument list from another application that takes over a minute until it is restarted after such a crash (this is no fun) and I really searched everywhere, the only thing I didn't consider until the very end was that bufpos might not be initialized.

It will not be initialized. Is this a bug or a feature?

Bernd

Reply by email

Bernd
to Bernd

This seems to happen only when it is a library. when I change library to program and compile it then the notices are gone. Also I cannot reproduce it with a program.

Compiler is 2.4.3 on windows 32 bit, I downloaded the latest snapshot of Lazarus+fpc-2.4.3 yesterday.

Reply by email

Bernd
to Bernd
library project1;
{$mode objfpc}{$H+}
function foo: LongInt;
var
  x: LongInt = 0;
begin
  Result := x;
end;
exports
  foo;
{$R *.res}
begin
end.

the following is in the diff when i switch from program to library:

***************
*** 12,19 ****
pushl %ebp
movl %esp,%ebp
subl $8,%esp
- movl TC_P$PROJECT1_FOO$$LONGINT_defaultx,%eax
- movl %eax,-8(%ebp)
movl -8(%ebp),%eax
movl %eax,-4(%ebp)
movl -4(%ebp),%eax

These two assembler statements are missing when compiled as library, but the TC_P$PROJECT1_FOO$$LONGINT_defaultx
in the data section at the end is still there and there:

.section .data.n_tc_p$project1_foo$$longint_defaultx .balign 4
.globl TC_P$PROJECT1_FOO$$LONGINT_defaultx
TC_P$PROJECT1_FOO$$LONGINT_defaultx:
.long 0

Reply by email

Mattias Gaertner
to Bernd: procedure analyzeHistory(...a lot of arguments...); stdcall; var i: LongInt;…
Show quoted text 28 lines
procedure analyzeHistory(...a lot of arguments...); stdcall; var i: LongInt; bufpos: LongInt = 0; balance: Double = 0; curtime: LongInt; begin [...] I did a lot of C in the last 6 months and almost no pascal. I'm not really sure anymore if i am confusing something or what is going on. The above will compile fine, except some little notes Note: Local variable "$defaultbufpos" not used Note: Local variable "$defaultbalance" not used Somewhere I have read (and I could swear I did it already) that this is the syntax to initialize a variable. I just had a session of over an hour and dozens of crashes because bufpos is an index into some complicated array that comes via the argument list from another application that takes over a minute until it is restarted after such a crash (this is no fun) and I really searched everywhere, the only thing I didn't consider until the very end was that bufpos might not be initialized. It will not be initialized. Is this a bug or a feature?

Please create a bug report. Not for lazarus, on the fpc bug tracker. Include all the information you gave here.

Mattias

Reply by email