structure

Structures and Unions in C, determining size and accessing members

。_饼干妹妹 提交于 2019-12-10 18:17:20
问题 All, Here is an example on Unions which I find confusing. struct s1 { int a; char b; union { struct { char *c; long d; } long e; }var; }; Considering that char is 1 byte, int is 2 bytes and long is 4 bytes. What would be the size of the entire struct here ? Will the union size be {size of char*}+ {size of double} ? I am confused because of the struct wrapped in the union. Also, how can I access the variable d in the struct. var.d ? 回答1: With no padding, and assuming sizeof(int)==sizeof(char *

Python ctypes - dll function accepting structures crashes

孤者浪人 提交于 2019-12-10 16:57:21
问题 I have to access a POS terminal under ms windows xp. I am using python 2.7. The crucial function in the DLL I load that does the payment accepts two pointer to structures, but it crashes returning 1 (Communication error) but without further messages. Please note that when the payment function is called, not all the elements of POSData structure receive a value. Other function I tried (GetVersion) does work. Here specifications and my code: typedef struct { char IPAddress[16]; //xxx.xxx.xxx

Should I declare and check if variables exist in PHP?

大憨熊 提交于 2019-12-10 16:45:28
问题 I've noticed on XAMPP that strict error reporting is on and I get undefined index errors now. I just have two small questions (I'm still learning here): I know you don't have to declare variables in PHP but is there any advantage to declaring them anyway? If not, why do I get errors when strict error reporting is on when I don't define them? When I use get variables for example, I check for their value before I run a function like if($_GET['todo'] == 'adduser') runFunctionAddUser(); This

C++ getting rid of Singletons: alternative to functors and static methods

孤街浪徒 提交于 2019-12-10 16:33:53
问题 My noble quest is to get rid of singletons and static classes. Background: I have the following structures: Cmd Frequently instantiated object, it holds a name of the command (string), and functor to the static method of any class as a pointer. It is typically created in main classes such as Input, Console, Render, etc. and refers to methods within the class that it is created in, giving a runtime verbal interface to those methods. Cmds also interpret parameters in a form of a string array,

Why doesn't this C++ code give compilation error?

狂风中的少年 提交于 2019-12-10 16:26:54
问题 #include<iostream> using namespace std; struct a{ int e; struct abc *d; }; struct abc{ int c; }; int main() { return 0; } I have defined the struct abc after definition of struct a in which i have declared a structure pointer for abc . This is supposed to throw compilation error because abc is used before its declaration. But, it doesn't, why? Whereas when i replace it with just struct abc d instead of struct abc *d , it is giving compilation error as expected. 回答1: This declaration struct

Java - Force implementation of an implemented method

橙三吉。 提交于 2019-12-10 15:44:42
问题 I have three classes which I have a problem with. They are named: GameScene, StageScene, StageOne. My problem is that I want to implement initialize in StageScene, but still force StageOne to implement it, so that whenever someone uses a StageOne object (stageOne.initialize()), initialize would be run for both StageScene and StageOne. Anyone know how this could be done? public abstract class GameScene { public abstract void initialize(); } public abstract class StageScene extends GameScene {

Initialising C structures in C++ code

冷暖自知 提交于 2019-12-10 15:23:30
问题 Is there a better way to initialise C structures in C++ code? I can use initialiser lists at the variable declaration point; however, this isn't that useful if all arguments are not known at compile time, or if I'm not declaring a local/global instance, eg: Legacy C code which declares the struct, and also has API's using it typedef struct { int x, y, z; } MyStruct; C++ code using the C library void doSomething(std::vector<MyStruct> &items) { items.push_back(MyStruct(5,rand()%100,items.size()

Passing structure containing an array of structures between C and C# (DLL and P invoke)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 15:22:49
问题 I have C dll with some complicated struct and I ma really a newbie in C#: typedef struct { int a; int b; } simple_struct; typedef struct { int d; int e; simple_struct f[20]; short g; simple_struct h[20]; short i; } complex_struct; The issue is that I am not able to interface my C# application with this structure!! In the DLL there is a function GetData(complex_struct* myStruct) and I shoud call it from C#, so I created: [StructLayout(LayoutKind.Sequential, Pack = 1)] unsafe struct simple

MVC - User input validation: controller, model or both [duplicate]

邮差的信 提交于 2019-12-10 14:19:32
问题 This question already has answers here : validation in mvc php (2 answers) Closed 6 years ago . I know questions like this one have been asked various times on stackoverflow, but even after having read those, I remain confused. I would like to gain clarity as to where form validation is supposed to be handled through demonstrating an issue with an example. Let's say I have a form on my website, with a field that somebody fills out and subsequently submits. The model would like the controller

In case of bit fields, which one is better to use, unsigned char or unsigned int and why?

廉价感情. 提交于 2019-12-10 14:13:43
问题 I just want to know about following structure declarations. Which one is better to use for memory allocation and why? And what about padding in case of unsigned char and unsigned int? struct data{ unsigned char a:3; unsigned char b:4; }; and struct data{ unsigned int a:3; unsigned int b:4; }; 回答1: Bit fields should be declared with type signed int , unsigned int . Other types may or may not be supported. From Atmel in the C Standard, only “unsigned (int)” and “int” are acceptable datatypes