首页 文章
  • 3 votes
     answers
     views

    Julia - 结构内部的C struct存储为Julia中的指针

    我正在使用一个C库,其中一个结构包含另一个结构(不是指针): typedef struct { int a; double b; } A; typedef struct { A a; A b; int c; } B; 示例初始化: B* mkB() { A a = {2, 3.0}; A b = {4, 5.0}; B* rv =...
  • 41 votes
     answers
     views

    函数ACTUALLY如何在C中返回struct变量?

    函数返回值如何对我来说是清楚的,只是为了启动: int f() { int a = 2; return a; } 现在 a 获取堆栈中的内存并且它的寿命在 f() 内,以便返回它将值复制到一个特殊寄存器的值,该寄存器由调用者知道被调用者已经为他放置了值 . (由于返回值持有者特殊寄存器大小的大小是有限的,这就是为什么我们不能返回大对象因此如果我们想要返回对象函数的高级语言实际上将堆中对...
  • 17 votes
     answers
     views

    将模板类专门化为结构

    我刚刚使用以下方法专门针对用户定义类型 std::hash : template<> struct hash<...> {...}; 当VC10向我发出警告时: 警告C4099:'std :: hash <_Kty>':使用'struct'现在看到的'class'首次看到的类型名称 我发现它的标准库声明 std::hash 为 class ,而标准(或我最...
  • 68 votes
     answers
     views

    如何在C#中将结构转换为字节数组?

    如何在C#中将结构转换为字节数组? 我已经定义了这样的结构: public struct CIFSPacket { public uint protocolIdentifier; //The value must be "0xFF+'SMB'". public byte command; public byte errorClass; publ...
  • -1 votes
     answers
     views

    fread无法读取文件

    我这里有一个嵌套结构 . typedef struct { struct_one one; struct_two two; struct_three three; } outermost_struct; 将指针传递给函数中的外部结构 outermost_struct settings readFileInStruct(settings_file, &a...
  • 0 votes
     answers
     views

    重载ObjC结构为C无序容器哈希支持

    我创建了 std::unordered_map<CGPoint, unsigned int> ,显然,要使它工作,我应该为它编写哈希函数: namespace std { template<> struct hash<CGPoint> { inline size_t operator()(const CGPoint & v) co...
  • 1 votes
     answers
     views

    Clang和Visual C结构对齐兼容性问题

    我们遇到了结构内存打包和对齐问题 . Android并不尊重#pragma pack(push,<n>),它在我们的代码库中有数百个位置 . 这是导致段错误的原因 . Android Clang编译器在结构或类上需要__ attribute __ decorator,例如: struct __attribute__((packed, aligned(8))) Test { ch...
  • -2 votes
     answers
     views

    在构造函数中初始化struct的向量

    我不知道如何在构造函数中初始化struct的向量 . 谁能给我指点? ^^ 这是我的结构: struct Point { int x; int y; }; 这是我的头文件: class ShapeTwoD { private: string name; bool containsWarpSpace; vector<Point> vertices; public: ShapeT...
  • 0 votes
     answers
     views

    调用ResetDC时崩溃,devmode从编组结构复制到字节数组

    通过我的Devmode时,我在调用ResetDC时收到System.AccessViolationException . 我正在做以下事情.. // create and marshall the devmode to a byte array. DEVMODE myDevmode = new DEVMODE {dmSize = (short) Marshal.SizeOf(typeof (DE...
  • 83 votes
     answers
     views

    Swift和mutating结构

    当谈到在Swift中改变值类型时,有些事情我并不完全理解 . 正如"The Swift Programming Language" iBook所述: By default, the properties of a value type cannot be modified from within its instance methods. 因此,为了使这成为可能,我们可以在结构...
  • 0 votes
     answers
     views

    将int和bytearray转换为ByteString Python struct Socket

    我需要通过套接字向服务器发送1 int和1 bytearray(200) . socket.send()函数只接受一个字符串,所以我需要int和bytearray作为一个字符串中的字节 . 我尝试将两者都转换为带有struct.pack()的字符串,这对于int而言并不适用于bytearray . s = socket.socket(socket.AF_INET, socket.SOCK_STR...
  • 0 votes
     answers
     views

    如何将c中的char []复制到我的struct中

    我试图通过UDP套接字发送我的结构 . struct Packet {int seqnum; char数据[BUFFERSIZE]; }; 所以发件人我有 bytes = sizeof(packet); char sending[bytes]; bzero(sending, bytes); memcpy((void *) sending, (void *) &packet, sizeof(...
  • 82 votes
     answers
     views

    你如何在C中创建一个结构数组?

    我正在尝试制作一个结构数组,其中每个结构代表一个天体 . 我没有试图实现我在各种线程和StackOverflow上看到的技术(例如Array of structs in C和C - initialize array of structs),但并非所有技术都适用 . 对于那些已经阅读过这一点的人的进一步信息:我不需要任何这些是动态的,我知道/事先确定一切的大小 . 我还需要将它作为一个全局数组,因为...
  • 0 votes
     answers
     views

    C.动态结构数组

    我想创建struct player的动态数组 . 我知道struct的大小,所以我不想为每个struct分配内存 . 所以我定义 struct player { uint32_t efficiency ; uint32_t number; } ; struct array { size_t size; struct player data[]; }; 但在我...
  • 1 votes
     answers
     views

    使用struct本身的类型定义struct参数

    我正在尝试将BFS算法发送到Matrix中,以获得从我的位置到BFS找到的第一个可访问元素的最短路径 . Matrix由定义如下的节点组成: struct node { int distance = -1; node parent; Pos position; //Direction to get into the actual node from the par...
  • 0 votes
     answers
     views

    将结构的字段和不同类型的值写入Go中的文件

    我正在编写一个简单的程序,它从表单中获取输入,用接收到的数据填充结构的实例,并将接收到的数据写入文件 . 我现在有点陷入困境,想出了迭代填充结构并将其内容写入文件的最佳方法 . 有问题的结构包含3种不同类型的字段(整数,字符串,[]字符串) . 我可以迭代它们但我无法得到它们的实际类型 . 使用print语句检查下面发布的代码,发现它们的每个类型都以结构形式返回,而不是前面提到的字符串,int等 ...
  • 14 votes
     answers
     views

    Golang反射:无法设置包装结构的接口字段

    我正在尝试实现一个方法,该方法可以更改可以具有任意结构的对象中的字段值 . 当我有一个指向结构的指针时,字段的转换没有问题 . 但是,当我的接口没有包装指向结构的指针但结构本身时,我无法改变字段,简而言之: // The following doesn't work var x interface{} = A{Str: "Hello"} // This panics: refl...
  • 0 votes
     answers
     views

    Golang SQL扫描结构奇怪

    请想象一下这样的表格: FirstName, LastName, Fee, Opt_Out String String Int TinyInt(4) 这样的结构: type Dude struct { Firstname string Lastname string Fee int Opt_out int } 为了简短起见:我...
  • 3 votes
     answers
     views

    如何在Golang中将* sql.Rows转换为键入的JSON

    本质上,我试图在MySQL数据库上运行查询,将数据转换为JSON并发送回客户端 . 我尝试了几种方法,所有“简单”方法都会导致将所有JSON作为字符串发回 . 我需要将其作为带有[] float64值的键(字符串)发回 . 这样我就有一个与密钥相关的数据数组 . 此外,这需要一个类型 . 到目前为止我发现的最好的方法是将所有数据构建到一个结构中,对其进行编码并将其发送回ResponseWriter...
  • 107 votes
     answers
     views

    如何在结构中定义多个名称标记

    我需要从mongo数据库中获取一个项目,所以我定义了一个像这样的结构 type Page struct { PageId string `bson:"pageId"` Meta map[string]interface{} `bson:"meta"` } 现在我还需要将它编码为JSON,但它将字段编码为大...
  • -1 votes
     answers
     views

    如何在struct char c上搜索?

    #include<stdio.h> #include<stdlib.h> //libraries #include<string.h> #define ARRAY_SIZE 4 //define the array size is 4 Declare a Person structure containing the following two data ...
  • 2 votes
     answers
     views

    C动态结构(malloc和free)

    我正在尝试学习C,C编程的基础知识,所以我从“C”开始 . 我有很多使用Java和VB编程的经验 . 但“C”是我想学的东西 . 所以我遇到了一个问题,试图理解“malloc”和“free”函数 . 我在Windows 98上使用Borland C 4.5和Visual C 6.0 . - (只是一个测试环境,想学习非常基础和早期的Windows编程) . 请参阅此代码: struct Stri...
  • 0 votes
     answers
     views

    为指向函数内部结构的指针分配内存

    我正在尝试编写一个单独的程序,该程序调用一个函数来为一定数量的“学生”结构动态分配内存 . 我的主程序太大而不能搞乱所以我创建了一个较小的程序来帮助我更容易地弄清楚我在做什么: #include <stdio.h> #include <stdlib.h> #include <string.h> #include "memtest.h" vo...
  • 1 votes
     answers
     views

    c仅分配函数调用返回的struct的一部分

    我有以下结构: struct foo{ int a[4]; int b[4]; } 我有以下功能: foo get_foo() { foo ret_val; <..some assignments here..> return ret_val; } 现在,我的主要代码: void* process_a() { int* pa = ge...
  • 35 votes
     answers
     views

    Structs是否总是堆栈分配或有时堆分配?

    我的印象是在C#中,struct元素在堆栈上分配,因此从创建它们的方法返回时会消失 . 但是如果我将struct-values放在一个列表中并返回它会发生什么?元素幸存下来 . Are struct instances sometimes allocated on the heap? internal struct Stru { public int i; } internal clas...
  • 1 votes
     answers
     views

    堆内存:8字节结构的16字节间隙

    我正在使用以下代码创建新节点并将其插入到链接列表中,随后将其释放 . // the node struct node { int data; struct node *next; }; // returns a pointer to a new node with data struct node *new_node(int data) { struct node *n...
  • 2 votes
     answers
     views

    如何使用image :: ImageBuffer作为成员创建Rust结构?

    我正在使用image crate来进行图片处理,并希望创建一个小包装器以使我的代码更有趣 . extern crate image; const BLACK: [u8; 4] = [0, 0, 0, 255]; const WHITE: [u8; 4] = [255, 255, 255, 255]; const RED: [u8; 4] = [255, 0, 0, 255]; pub stru...
  • 1 votes
     answers
     views

    Simulink:来自总线输入的单个信号输出(基于信号名称)

    我有一个复杂的Simulink模型,并希望在子系统中生成一个简单的错误消息信号,从大量的传入错误观察信号 . 这些输入信号在一个总线中组织,并且始终为0,在发生错误时执行:然后有一个值到边缘 . 错误消息应包含单个位代码,该代码是为excel列表中的每个错误名称和错误值定义的 . 如何将此错误代码分配给具有上升沿的特定错误信号?我需要类似查找功能的东西: for(每个信号):如果信号有边缘值,请...
  • 3 votes
     answers
     views

    是否在C中定义了结构类型的对齐方式?

    我知道C结构中的成员与他们需要的任何边界对齐 . struct S { uint8_t ui8; /* invisible padding here */ uint32_t ui32; }; 我的问题是,是否定义了 struct S 实例的对齐方式? struct S my_s; 是否定义了 my_s 的对齐方式?是否 struct S 作为其第一个成员 ui32 是否重要? 我搜...
  • 3 votes
     answers
     views

    结构的最佳解决方案,超过16个字节

    我有一种我认为用它作为结构的类型 . 它代表单一值 这是不可改变的 但问题是,它有6个int字段 . 那么我应该为这种类型使用哪种解决方案? 继续使用struct? 改为上课? 或将6个整数打包成int数组,因此它只有一个字段 EDIT 具有6个整数字段的struct的大小是24个字节,这是很难传递的 . struct的推荐大小不超过16个字节

热门问题