# Executing a pop\_back() function call on empty queue

**URL:** <https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, queues-systemverilog\
**Created:** [March 9, 2023, 1:25pm UTC](https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360 "2023-03-09T13:25:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asvpuneet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@asvpuneet](https://verificationacademy.com/forums/u/asvpuneet)\
**Post date:** [March 9, 2023, 1:25pm UTC](https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360/1 "2023-03-09T13:25:17Z")

</div>

When calling a pop\_back() function on an empty queue, the simulation doesnt fail

```verilog

module GRG_queue1;

  typedef struct {
    string txt ;
    byte unsigned b ;
    int array[];
  } T;
  
  typedef enum {
                HELLO,
                UNKNOWN,
                RESET, 
                SET
    } wire_state_t;
  

  T q[$];
  
  wire_state_t wire_q[$];
  int test_q[$];
  
  wire_state_t map_q[];
  
  
  initial begin
    q.push_back('{"abc", 123, '{4, 5, 6}});
    q.push_back('{"def", 156, '{9, 8, 7}});
    $display("%p", q);
    
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    $display("wire_q: %s", wire_q.pop_back());
    
    $display("map_q: %s", map_q[0]);
    
    $display("wire_q size: %d", wire_q.size());
    
    $display("test_q: %d", test_q[0]);
    
    
  end

endmodule

```

**Output:** \_\_

wire\_q: HELLO  
wire\_q: HELLO  
wire\_q: HELLO  
wire\_q: HELLO  
wire\_q: HELLO  
map\_q: HELLO  
wire\_q size: 0  
test\_q: 0

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [March 9, 2023, 1:42pm UTC](https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360/2 "2023-03-09T13:42:07Z")

</div>

From the LRM:

**7.10.2.5 Pop\_back()**  
The prototype of the pop\_back() method is as follows:  
**function element\_t pop\_back();**  
The pop\_back() method removes and returns the last element of the queue.  
If this method is called on an empty queue:  
— Its return value shall be the same as that obtained by attempting to read a nonexistent array element  
of the same type as the queue’s elements (as described in Table 7-1 in 7.4.6);  
— It shall have no effect on the queue and may cause a warning to be issued.

Based on the LRM, everything is working correctly. You may get a warning message, but a warning isn’t required.

---

<div class="post-metadata">

**Author:** ![asvpuneet](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@asvpuneet](https://verificationacademy.com/forums/u/asvpuneet)\
**Post date:** [March 9, 2023, 2:47pm UTC](https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360/3 "2023-03-09T14:47:58Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360/2):_

What is the use-case for sending the default value. In other languages, we receive a null-object access

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [March 9, 2023, 6:02pm UTC](https://verificationacademy.com/forums/t/executing-a-pop-back-function-call-on-empty-queue/41360/4 "2023-03-09T18:02:56Z")

</div>

Table 7-1 describes the return types/values when there are no elements available. In some cases, you will get null-objects. For other types, you will get default values.
