Are the following equivalent in C?
// #1
struct myStruct {
int id;
char value;
};
typedef struct myStruct Foo;
// #2
typedef struct {
int id;
char value;
} Foo;
If not, which one should I use and when?
(Yes, I have seen this and this.)
...
I'm having a problem creating a C# P/invoke wrapper around a third party C library. In particular, the library has a method with the signature
int command(SomeHandle *handle, int commandNum, void *data, int datasize);
It is a wildcard method that does different things depending on commandNum. data can be a pointer to anything, like a s...
Given:
struct objStruct {
int id;
int value;
};
typedef struct objStruct Object;
Is there a shortcut to allocate and initialize the object, something like a C++ constructor?
It could even be a preprocessor macro. Whatever makes the code shorter and more readable than this:
Object *newObj = malloc(sizeof(Object));
// successf...
i have a WCF Method that receives array of structs.
the struct contains two strings "Key" and "Value":
public struct mydata
{
public String key;
public String value;
}
[ServiceContract]
public interface IBasicService
{
[OperationContract]
[WebGet(UriTemplate = "ReceiveStructsOfData?myDataArray={???????? WHAT DO I WRITE...
namespace MyNamespace
{
public struct MyStruct
{
public string MyString;
public int MyInt;
public bool MyBool;
}
public class MyClass
{
private List<MyStruct> MyPrivateVariable;
public List<MyStruct> MyVariable
{
get
{
if (MyPriv...
Hi, I'm trying to compile the following code under VC2010.
struct CircValRange
{
double a,b; // range: [a,b)
};
template <struct CircValRange* Range>
class CircVal
{
// todo
};
const CircValRange SignedDegRange= {-180., 180.};
CircVal<SignedDegRange> x;
I'm getting
error C2970: 'CircVal' : template parameter 'Range' : 'S...
I am currently working on a project using network simulator 2. When I add variable inside the structure re_block, the program compiles but gives me segmentation fault during runtime. When i declare the variable as static there is no runtime error. Someone please explain this.
struct re_block {
# if __BYTE_ORDER == __BIG_ENDIAN
u_int16_...
Hi! I've got two forms of struct declaration in the function scope. As far as I could see the bellow-listed snippet woks just fine. The question is what's the difference between the two declaration ways? Is that only a semantic question or there is something tricky under the covers?
package main
import "fmt"
func main() {
type Pe...
Is it 12 bytes or 16 bytes when stored in a List<DataPoint>?
public struct DataPoint
{
DateTime time_utc;
float value;
}
Is there any sizeof function in C#?
...
I was curious on the overhead of a large structure vs. a small structure in using operators + and * for math. So I made two struct, one Small with 1 double field (8 bytes) and one Big with 10 doubles (80 bytes). In all my operations I only manipulate one field called x.
First I defined in both structures mathematical operators like
pub...
Update: It occurred to me after posting this question that the main downside of this idea would simply be that such a type would be easy to use improperly. That is, the type would have to be used in a very specific way to draw any benefits. What I originally had in mind was something that would be used like this (sticking with the Square...
I'm trying to figure out some C code so that I can port it into python. The code is for reading a proprietary binary data file format. It has been straightforward thus far -- it's mainly been structs and I have been using the struct library to ask for particular ctypes from the file. However, I just came up on this bit of code and I'm at...
Can you make a struct that behaves like one of the built-in classes where you can assign the value directly without calling a property?
ex:
RoundedDouble count;
count = 5;
Rather than using
RoundedDouble count;
count.Value = 5;
...
I have a Web service set up using Zend_Soap, and some public methods in that Web service.
The fact is i want to return a complex type.
For instance, if i want to return a bidimensional array, like a rowset of a table how should i specify the doc block?
This is one of my cases. I want to return an array each element having an int and two...
In C++ and Java, data structures can have private, public and protected regions. I'd like to port this concept to a C language program I am writing.
Are there any idioms for implementing private or protected function pointers and data fields in a C struct?
I know that C structs are public, I'm looking for an idiom to help hide some i...
For test purpose, I want to compare two structs (of unknown type T) marshaled from unmanaged code.
Because they may contain some packing in unmanaged representation, it is inappropriate to convert whole struct to byte array and then compare byte by byte:
int size = Marshal.SizeOf(typeof(T));
IntPtr buf1 = Marshal.AllocHG...
hey, i got an question about what is going on in the next code:
typedef struct {
double re,im;
} Complex;
Complex ComplexCreate(double r=0.,doublei=0.)
{
Complex c;
c.re=r;
c.im=i;
return c; // problem with this line
// my question is : is c getting duplicated and returning or does it return not...
say a define a struct in header file of c++, foo.h
typedef struct {
...
}foo;
in .c file I include the foo.h, then
foo* fooPtr;
will it work?
...
I remember touching on this subject during a class on programming languages. I vaguely remember that a struct could be seen as a mathematical tuple. Is it possible to describe a class or an object in a similar fashion?
...
I know when I have to print I use p->real and so on but what should I write when I am reading numbers using scanf?
#include <stdio.h>
typedef struct {
int real;
int imaginary;
} complex;
void read(complex*);
void main() {
complex c;
read(&c);
}
void read(complex* p){
/*what to write in scanf*/
}
...