How can the initialisation of a struct be used as variable in a function call. ANSI-C Version

I am writing C89, C90, Ansi-C Code. One of my functions requires a struct as a parameter. I want to call the function with the initialisation of that struct rather tan creating a struct forst then passing it to the function.

Here are some snippets wich work.

typedef struct { char* EventName; char* Message; } Event; Event myEvent = { .EventName = "infomessage", .Message = "Testmessage" }; Notify(myEvent);

and here is what i would like to write but wich doesnt work

Notify({.EventName = "infomessage", .Message = "Testmessage"});

or even better

Notify({"infomessage", "Testmessage"});

EDIT: LabCVI is using the ISO 9899:1990 standard.

-------------Problems Reply------------

Use the compound literal (Event){"infomessage", "Testmessage"}, ie

Notify((Event){"infomessage", "Testmessage"});

Category:function Views:1 Time:2010-12-30

Related post

  • same named struct(class) with different variables 2012-02-02

    I have different graphic classes like histogram class, ma class.. they have common variables but different property variables. For example all classes have an id but there are different property variables for every classes. For example, column_width

  • Initialising c-style structs 2012-01-23

    I have a header that defines c style structs that are to be passed over a boundary on a c++ DLL. This header and DLL will potentially be used by c++, java and c applications. I want to initialise these structs in someway that allows the user to speci

  • Union initialisation in a struct 2012-04-16

    I've been browsing stackoverflow concerning the problem of initialising a union in a struct but I didn't manage to get it right. Here is my struct typedef struct dc_netif_filter { unsigned char filter_type; union { uint32_t itf_nb; char * buf; } valu

  • How to access members of a `struct' according to a variable integer in C? 2009-05-20

    Suppose I have this struct (which incidentally contain bit-fields, but you shouldn't care): struct Element { unsigned int a1 : 1; unsigned int a2 : 1; ... unsigned int an : 1; }; and I want to access the i'th member in a convenient way. Let's examine

  • Someone is using the struct name as a variable name too. What does the code really say? 2010-04-20

    This morning we found an old chunk of code that was causing a library call to crash. struct fred { int a; int b; int c; }; fred fred[MAX_SIZE+1]; memset( fred, 0, sizeof(fred) * MAX_SIZE+1 ); It appears that the sizeof(fred) may have been the full ar

  • LLVM: Passing a pointer to a struct, which holds a pointer to a function, to a JIT function 2010-06-05

    I have an LLVM (version 2.7) module with a function that takes a pointer to a struct. That struct contains a function pointer to a C++ function. The module function is going to be JIT-compiled, and I need to build that struct in C++ using the LLVM AP

  • Does a field of a struct count as a variable? Does an element of an array count as a variable? 2010-12-15

    I know both arrays and structs count as variables, but do their fields/elements? I'm trying to write some documentation about a program that deals with deeply nested structs and arrays, but don't know if I can refer to these fields/elements as variab

  • How do I specify a struct as the return value of a function in RubyFFI? 2011-03-20

    I have to load several functions that return structures from the library itself. attach_function 'fn_name', [], # ... What do I put here? RubyFFI's Wiki pages seem to be outdated, so I'm a little lost here. How do I create a FFI::Struct, and how do I

  • C++ define class member struct and return it in a member function 2011-04-02

    My goal is a class like: class UserInformation { public: userInfo getInfo(int userId); private: struct userInfo { int repu, quesCount, ansCount; }; userInfo infoStruct; int date; }; userInfo UserInformation::getInfo(int userId) { infoStruct.repu = 10

  • How do I marshal a struct that contains a variable-sized array to C#? 2011-05-05

    How do I marshal this C++ type? The ABS_DATA structure is used to associate an arbitrarily long data block with the length information. The declared length of the Data array is 1, but the actual length is given by the Length member. typedef struct ab

  • D struct memory handling - return `this` from member function 2012-01-22

    uint ci = 0; struct S { uint i; this(int x) { i = ci; ci++; writeln("new: ", i); } this(this) { i = ci; ci++; writeln("copy ", i); } ~this() { writeln("del ", i); } S save1() // produces 2 copies in total { S s = this; return s; } auto save2() // pro

  • using a qsort to sort struct pointers by different variables 2012-03-23

    I am attempting to understand the c library qsort in the context of pointers to structs. Here is the existing code that I would like to manipulate: The structure: #define MAX_NAME 20 #define NUM_MONTHS 12 typedef struct EMP { char name[MAX_NAME+1]; i

  • Define functions in structs 2012-03-26

    Can we define functions in structs in C programming language? --------------Solutions------------- No, as functions are not data. But you can define function pointers inside a struct. struct foo { int a; void (*workwithit)(struct foo *); } You can't

  • Convenient C++ struct initialisation 2011-05-30

    I'm trying to find a convenient way to initialise 'pod' C++ structs. Now, consider the following struct: struct FooBar { int foo; float bar; }; // just to make all examples work in C and C++: typedef struct FooBar FooBar; If I want to conveniently in

  • Initialising an array of structs in Objective-C 2012-03-18

    I've been reading about this for a while and I'm not sure I have found a good answer. I'm trying to setup an array of 92 structs. It's a fixed length and will not change as it's effectively a lookup table. I thought that the best way to do this was t

  • Should Local Variable Initialisation Be Mandatory? 2008-09-26

    The maintenance problems that uninitialised locals cause (particularly pointers) will be obvious to anyone who has done a bit of c/c++ maintenance or enhancement, but I still see them and occasionally hear performance implications given as their just

  • How much functionality is "acceptable" for a C++ struct? 2009-03-17

    My first post so please go easy on me! I know that there's no real difference between structs and classes in C++, but a lot of people including me use a struct or class to show intent - structs for grouping "plain old data" and classes for encapsulat

  • Default values in a C Struct 2009-04-14

    I have a data structure like this: struct foo { int id; int route; int backup_route; int current_route; } and a function called update() that is used to request changes in it. update(42, dont_care, dont_care, new_route); this is really long and if I

  • Are the members of a c struct guarenteed to be initalized to 0? 2009-10-01

    Title pretty much sums it up. When I declare a struct in C, am I guaranteed that the members will be initialized to some specific value, such as 0 for integer members? EDIT: So, let's say I have a struct that looks like: typedef struct { int a; } my_

Copyright (C), All Rights Reserved.

processed in 0.187 (s). 11 q(s)