warning: Static variable initialization requires explicit lifetime in this context

OP #6409185
Rate this post
• ▲ useful
▼ not useful
I've got a Verilog compilation complaint that I've been able to isolate 
in a stripped down version of my code:
1
module expLif ();
2
parameter  integer nmBits  = 1;
3
localparam integer highBit = nmBits - 1;
4
output             lssThn;
5
input [ highBit:0] leftOp;
6
input [ highBit:0] rightOp;
7

8
typedef enum { CORNER, E_LEAF, N_LEAF, SIDE, E_INTERIOR, N_INTERIOR } nodeType;
9
typedef struct packed
10
{ nodeType ndType;
11
   integer inLow;
12
   integer inHigh;
13
   integer out;
14
} node;
15

16
localparam integer nmNodes  = 2 * nmBits - 1;
17
localparam integer nmLevels = $clog2( nmBits) + 1;
18

19
localparam integer [ nmLevels:0] bases;
20

21
initial
22

23
begin
24
  integer lvl;
25
  integer pwr = 1;
26
  bases[ 0]   = 1;
27
  for (lvl = 1; lvl <= nmLevels; lvl = lvl + 1)
28
  begin
29
    bases[ lvl] = bases[ lvl - 1] + ((nmNodes + pwr >> lvl << 1) - 1);
30
    pwr       <<= 1;
31
  end
32
end
33

34
endmodule
The actual complaint when I try to simulate this with Icarus is:
1
D:\Hf\Verilog\Unpacked\Src\Common>\Icarus\bin\iverilog -g2009 -o expLif.vvp expLif.sv
2
expLif.sv:19: syntax error
3
expLif.sv:19: error: syntax error localparam list.
4
expLif.sv:25: warning: Static variable initialization requires explicit lifetime in this context.
5

6
D:\Hf\Verilog\Unpacked\Src\Common>
I want value (pwr) to be successive powers of two each time I go through 
one iteration of the loop. Can anyone tell me why this code doesn't work 
and/or what I need to do to fix it? Thanks in advance for any 
suggestions you can give me.
OP #6410182
Rate this post
• ▲ useful
▼ not useful
Klakx: "I think the error is more important. Try this localparam integer 
bases [ nmLevels:0];" I'm fine with fixing the error before dealing with 
the warning. But I
made the change you suggested:
1
module expLif ();
2
parameter  integer nmBits  = 1;
3
localparam integer highBit = nmBits - 1;
4
output             lssThn;
5
input [ highBit:0] leftOp;
6
input [ highBit:0] rightOp;
7

8
typedef enum { CORNER, E_LEAF, N_LEAF, SIDE, E_INTERIOR, N_INTERIOR } nodeType;
9
typedef struct packed
10
{ nodeType ndType;
11
   integer inLow;
12
   integer inHigh;
13
   integer out;
14
} node;
15

16
localparam integer nmNodes  = 2 * nmBits - 1;
17
localparam integer nmLevels = $clog2( nmBits) + 1;
18

19
localparam integer bases [ nmLevels:0];
20

21
initial
22

23
begin
24
  integer lvl;
25
  integer pwr = 1;
26
  bases[ 0]   = 1;
27
  for (lvl = 1; lvl <= nmLevels; lvl = lvl + 1)
28
  begin
29
    bases[ lvl] = bases[ lvl - 1] + ((nmNodes + pwr >> lvl << 1) - 1);
30
    pwr       <<= 1;
31
  end
32
end
33

34
endmodule
and then when I used Icarus to attempt to simulate it I got:
1
E:\Hf\Verilog\Unpacked\Src\Common>\Icarus\bin\iverilog -g2009 -o expLif.vvp expLif.sv
2
expLif.sv:19: syntax error
3
expLif.sv:19: error: syntax error localparam list.
4
expLif.sv:25: warning: Static variable initialization requires explicit lifetime in this context.
5

6
E:\Hf\Verilog\Unpacked\Src\Common>
so the change you suggested doesn't appear to have fixed the error. Do 
you have any other ideas on what might be causing the error and/or how I 
can fix it? Anybody know what I'm doing wrong here?

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.