dongzhi1904 2011-02-18 04:27
浏览 51
已采纳

键入常量声明列表

I wish to create an "enum-like" list of constants with the following properties:

  1. The values of each identifier are sequential, with a few gaps. (I believe iota and the blank identifier help in this regard).
  2. The identifiers are private to the module.
  3. The constants can only be compared with other constants of the same type.

The enumeration is based on the enum fuse_opcode from FUSE. Here's some code for what I'm trying to accomplish (and also very wrong):

const Opcode (
    _ = iota // skip 0
    lookupOp
    forgetOp
    getattrOp
    setattrOp
    readlinkOp
    symlinkOp // 6
    _ // skip 7
    mknodOp // 8
    // et cetera ad nauseam
)
  • 写回答

3条回答 默认 最新

  • dongtao4319 2011-02-18 05:23
    关注

    Here's the Go code for the FUSE opcodes. It was created from enum fuse_opcode. Typically you would write a script to do that; I used a text editor. Since the constant values match the C enum values, explicit values are used.

    package fuse
    
    type opCode int32
    
    const (
        opLookup      = 1
        opForget      = 2
        opGetattr     = 3
        opSetattr     = 4
        opReadlink    = 5
        opSymlink     = 6
        opMknod       = 8
        opMkdir       = 9
        opUnlink      = 10
        opRmdir       = 11
        opRename      = 12
        opLink        = 13
        opOpen        = 14
        opRead        = 15
        opWrite       = 16
        opStatfs      = 17
        opRelease     = 18
        opFsync       = 20
        opSetxattr    = 21
        opGetxattr    = 22
        opListxattr   = 23
        opRemovexattr = 24
        opFlush       = 25
        opInit        = 26
        opOpendir     = 27
        opReaddir     = 28
        opReleasedir  = 29
        opFsyncdir    = 30
        opGetlk       = 31
        opSetlk       = 32
        opSetlkw      = 33
        opAccess      = 34
        opCreate      = 35
        opInterrupt   = 36
        opBmap        = 37
        opDestroy     = 38
        opIoctl       = 39
        opPoll        = 40
        opNotifyReply = 41
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动