小编Nic*_*eed的帖子

foo(void)与foo(void *)

从功能和语法上来说,原型为int foo(void)和的函数之间是否有区别int foo(void *)

我知道,例如之间的差异,int bar(int)以及int bar(int *)-其中之一是寻找一个int,另一种是找一个int指针。void行为是否相同?

c c++ function-prototypes

9
推荐指数
2
解决办法
170
查看次数

如何在执行时在perl脚本中显示子例程及其名称的数量?

考虑下面的Perl脚本script.pl作为示例:

use strict;
use warnings;
sub f1
{statements}
sub f2
{statements}
sub f3
{statements}
f1();f2();f3();
Run Code Online (Sandbox Code Playgroud)

当我执行脚本时,它应该显示如下输出:

./script.pl

子程序数:3个子程序
名:f1 f2 f3

regex linux perl

3
推荐指数
2
解决办法
125
查看次数

结构的内存大小

我有以下结构。

    typedef struct {
        int8_t     tmsi[4];        /**< TMSI value. */
        int8_t     ptmsi[4];       /**< PTMSI value. */
        int8_t     gprs_attach_status;
        int8_t     rplmn[3];               /**< PLMN info */
        uint32_t T3212_value;
        uint32_t T3312_value;
        uint8_t   cs_reject_cause;
        uint8_t   ps_reject_cause;
        int8_t     qos[28];  /** QoS  parameters for a PDP context. */
        int8_t     pdp_addr_len;
        int8_t     pdp_address[10];
        uint16_t apn_addr_len;   /**< APN address length. */
        int8_t     apn_address[20];   /**< APN address. */
    }nas_ftd_umts_nas_info_s_type_v01 ;
Run Code Online (Sandbox Code Playgroud)

此结构的大小(不带填充)应为83。但是在64位处理器上编译时,大小显示为84。编译器为pdp_address [10]分配了一个额外的字节。不确定为什么要分配此额外的字节。谁能让我知道原因呢?

我用以下代码检查了每个成员的偏移量:

#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) 

    int main()
    {
        temp a; 
        test_ping_req_msg_v01 t;
        nas_ftd_umts_nas_info_s_type_v01 info;
        nas_ftd_umts_network_info_s_type_v01 lte; …
Run Code Online (Sandbox Code Playgroud)

c c++

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

C#Monitor.Exit在Try/Catch中

我正在对旧的源代码进行故障排除,并且遇到了这样的声明:

if (Monitor.TryEnter(lockObj))
{
    try
    {
        //does something
        if (failing_condition)
        {
            Monitor.Exit(lockObj);
            throw new Exception("Oops!");
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            Monitor.Exit(lockObj);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

代码崩溃了 System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code.

有没有一种安全的方法来调用Monitor.Exit()失败的条件和正常的执行完成?

c# multithreading try-catch

0
推荐指数
1
解决办法
427
查看次数

标签 统计

c ×2

c++ ×2

c# ×1

function-prototypes ×1

linux ×1

multithreading ×1

perl ×1

regex ×1

try-catch ×1