小编Bro*_*nze的帖子

如何将对约束字符串的访问权限传递给Ada中的子程序

好的.我真的很讨厌这样简单的问题,但我已经完全阅读了三本不同的书籍,向我解释了访问类型和参数模式,我无法理解我做错了什么.

我在Ada中创建了一个简单的shell,因为我对此很感兴趣,并且我认为到目前为止这是一个很好的学习经历.这是我的代码:

with Ada.Text_IO;
with Execute_System;

procedure Main is
   package IO renames Ada.Text_IO;
   Input : aliased String(1 .. 255) := (others=> ' ');
   Last: Integer;

begin
   IO.Put_Line("Welcome to ash! This is an extreme work in progress.");
   Main_Loop:
   loop
      Input := (others=> ' ');
      IO.Put("ash> ");
      IO.Get_Line(Input, Last);
      if Input(Input'First..Last) = "quit" then
       exit Main_Loop;
      else
       Execute_System(Command => Input'Access);
      end if;
   end loop Main_Loop;
end Main;
Run Code Online (Sandbox Code Playgroud)

Execute_System()所做的是传递给Spawn,而后者又由GNAT.OS_Lib库提供.编译时得到的错误是:

main.adb:6:04: warning: aliased object has explicit bounds
main.adb:6:04: warning: declare without bounds (and with …
Run Code Online (Sandbox Code Playgroud)

pointers ada

3
推荐指数
1
解决办法
629
查看次数

在if-else语句中声明时,C++编译器会给出单元化变量警告

我确信这有一个简单的解释,但我有一些像这样的代码:

  RoutingTablePoolEntry rtpe;
  RoutingTablePoolEntry* rtpePtr;

  if (rtpeItr == m_rtpool.end()) {
    RoutingTableEntry* routeEntryPtr = m_nlsr.getRoutingTable()
      .findRoutingTableEntry(destRouter);

    if (routeEntryPtr == nullptr) {
      RoutingTablePoolEntry rtpe(destRouter);
    }
    else {
      RoutingTablePoolEntry rtpe(*routeEntryPtr);
    }

    RoutingTablePoolEntry* rtpePtr = addRtpeToPool(rtpe);
  }
  else {
    RoutingTablePoolEntry* rtpePtr = &(rtpeItr->second);
  }
  doSomeStuffWithRtpe()
Run Code Online (Sandbox Code Playgroud)

编辑:这是一些真正的代码.错误是否仍在变量范围内?我在这个例子中意识到,但这仍然是问题吗?我尝试了表单的条件初始化: RoutingTablePoolEntry rtpe(routeEntryPtr == nullptr? ... : ...);但这似乎也没有合作太多.

编辑#2:我是个白痴,对不起.原因非常清楚,我只是没有看到它.

rtpe = RoutingTablePoolEntry(destRouter)并且 rtpePtr = &(rtpeItr->second) 在很小的机会中,任何人都会这样做.

c++ compilation compiler-warnings

-1
推荐指数
1
解决办法
39
查看次数

标签 统计

ada ×1

c++ ×1

compilation ×1

compiler-warnings ×1

pointers ×1