Questions tagged [typedef]
In C and C++, the typedef keyword allows you to create an alias for a known data type.
3,087
questions
1
vote
2
answers
49
views
typedef with array in c
Something wrong with my understanding of typedef for arrays in C.
Code just not worked as expected. I provide some screenshot while debugging this simply code. And you can see there, that only firs ...
0
votes
1
answer
14
views
remove typedef from struct function pointer
The code below works as advertised. However, I don't quite understand the mechanism of "typdef" in this application (I understand its use for the struct) so I would like to remove them to ...
3
votes
3
answers
94
views
Defining function pointer in C?
Recently I came across a surprising way of defining a function pointer in C:
typedef void (func_type)(void);
func_type *func_ptr;
Is this a correct way of defining a function pointer?
If we define ...
-1
votes
2
answers
85
views
How is the typedef struct code used in C?
I have to add the roots to an custom datatype which is roots in this case.
(This is what I think about this issue)
So how do I do this?
Here is my code:
#include <math.h>
typedef struct { ...
0
votes
1
answer
72
views
How can I create a typedef representing a Dart record with named fields?
I would like to define a typedef representing a Dart record with named fields but am not sure what the syntax would be.
The code below shows how to define the typedef Command representing a record ...
1
vote
2
answers
52
views
How to redefine uint_least8_t for unit tests
I am trying to unit test code on x86 that uses uint_least8_t. On one of the targets this is actually a uint16_t so I'd like to be able to unit test with uint_least8_t being both uint8_t and uint16_t. ...
0
votes
1
answer
60
views
C typedef underscore aliases in declaration
pdfium's public headers often contain constructs like this
typedef enum _FPDF_DUPLEXTYPE_ {
DuplexUndefined = 0,
Simplex,
DuplexFlipShortEdge,
DuplexFlipLongEdge
} FPDF_DUPLEXTYPE;
typedef ...
1
vote
0
answers
50
views
Is there a way to have only one wrapper for two functions with different signatures
I have to define some wrapper function in order to expand the functionalities of the wrapped ones.
In general, the functions have this signature:
coco_problem_t f_<function_name>...
0
votes
1
answer
38
views
C - Structure with different amount of members / array size known at compile time
My Problem is the following, i hope someone can help me pls or knows a better way to do it:
The Platform is an embedded system with only static memory, so everything has to be known at compile time, ...
2
votes
2
answers
65
views
how to split cyclic dependency with 'using' directive
Suppose classes A and B. Each can construct the other:
// A.hpp
#pragma once
class B;
class A {
B foo();
};
// A.cpp
#include <A.hpp>
#include <B.hpp>
B foo(){ return B(); }
// B.hpp
#...
-1
votes
1
answer
131
views
Are typedef declarations for bare function types (ie: not function pointers) legal in C89/C90?
Let's consider the following code:
#include <stdio.h>
#include <string.h>
typedef int INTFUNC(char *, char *);
INTFUNC lencmp;
int main(void) {
printf("%d\n", lencmp("...
1
vote
2
answers
186
views
Is it really legal for K&R to write "PFI strcmp, numcmp;" where PFI is typedef'd as "int (*)(char *, char *)"?
In The C Programming Language (Kernighan and Ritchie, 2nd ed) on p147, the authors show a typedef declaration
typedef int (*PFI)(char *, char *);
(PFI stands for "pointer to function returning ...
0
votes
0
answers
82
views
Vscode intellisense error: variable "float32" is not a type name
This following code produces error "variable "float32" is not a type name" in visual studio code.
typedef float float32;
typedef struct
{
float32 real;
float32 imag;
} ...
1
vote
1
answer
76
views
exploit a function type to define a new function
Curious to know whether there have ever been proposals to extend the language and exploit a defined function type in a function definition.
A related question is:
Using a defined function type in a ...
0
votes
0
answers
21
views
VSCode intellisense says boost::shared_ptr requires 2 args gazebo transport
I am working with the c++ gazebo transport library (Ros2 Galactic, Gazebo 11 classic). I was confused as to why
gazebo::transport::NodePtr gives the error
namespace "gazebo::transport" has ...
0
votes
1
answer
36
views
SWIG typedef creates conflict across module boundary
I am writing a C# wrapper for the stepcode library (https://github.com/stepcode/stepcode) by using SWIG (version 4.1.1) as generator. The library is highly modularized, so there are situations where ...
4
votes
1
answer
136
views
Best practice for typedef'ing structs? [closed]
I've gone down a rabbit hole of questions about typedef, tag and struct namespaces, and leading _ being reserved by either the system libraries or the compilers. My question:
What is the best practice ...
1
vote
0
answers
85
views
Why isn't strncpy working to copy a string to a variable of a struct? [duplicate]
I have the following struct in my code:
typedef struct
{
uint64_t pulse;
fp_t volume;
fp_t factor; // Factor en pulsos / unidad de volumen
char *unit_volume;
char *unit_time;
} ...
2
votes
2
answers
62
views
Access data member from function pointer in struct
I gotta admit. I lack experience with C and therefore I am unsure how to implement a function for a struct. There are plenty of answers out there: Define functions in structs, Can I define a function ...
1
vote
3
answers
164
views
In C++ how to reuse a class definition as a different class
Say we have a class definition
class Foo {...};
I know we can reuse its definition with using or typedef
using Bar = Foo; // or typedef Foo Bar;
But they are treat as a same type, that is to say the ...
-1
votes
1
answer
100
views
Extern a type in C
I am trying to figure out a way to create a "template" type in C, which I can override by specific implementation. Right now I have a specific type defines in a header file:
typedef enum
{
...
0
votes
1
answer
58
views
Can a typedef alias be unraveled at run-time?
Say one uses typedef to alias data types.
For example:
typedef int signed_integer;
typedef unsigned int unsigned_integer;
However, via pre-processor macros, signed_integer and unsigned_integer could ...
0
votes
0
answers
10
views
Why i am not able to use the typedef with function pointer
Why its not working. Please bear with me, i am beginner
#include <stdio.h>
int fun(int a)
{
printf("Value of a is %d\n", a);
return a;
}
int main()
{
typedef int (*fun_ptr)(int)...
0
votes
1
answer
19
views
SWIG : convert item of a numpy array to a C++ typedef
Here is a minimal example (ubuntu 18.04, swig 4.2.0):
Var.hpp
#include <iostream>
typedef int MY_INT;
void printMyInt(MY_INT v)
{
std::cout << "MyInt is " << v << ...
0
votes
2
answers
93
views
How can I write a typedef for a function pointer to accept different types of arguments in c++?
Currently I have a function pointer to perform some actions based on the user inputs, like this:
typedef int(A::*FUNCPTR)();
std::map<const std::string, FUNCPTR> func_map;
func_map["sum&...
0
votes
2
answers
116
views
Call function implementing type on instance by a pointer
I'm trying to implement subscriber-publisher pattern. My base class Subscriber doesn't have a listener method, it declares type Handler instead. The idea behind this is that a derived class will be ...
1
vote
2
answers
122
views
Why does declaring nested structures in C using typedef cause an error?
So in one of my C classes, the teacher was using struct and not typedef struct. When I tried, it showed an error.
This one does not show any error
#include <stdio.h>
typedef struct {
...
0
votes
3
answers
170
views
typedef const char* vs. const typedef char*
I have noticed that constness on a typedef'ed pointer loses its ability to be converted implicitly to a const type of the un-typedef'ed type.
Since I am clearly lacking proper vocab to explain the ...
0
votes
0
answers
51
views
C struct definition naming
What is the purpose of adding the name of the struct after struct keyword, along with type alias?
Seems to me like the 2 definitions below would work and could be used in the exact same name, so I ...
2
votes
1
answer
88
views
How does a pointer typedef struct work in C?
I have learned that typedef allows me to give a struct a name that can be referenced without needing to specify struct before the name. For example, I can create an instance of Network 2 different ...
3
votes
2
answers
122
views
Pointer to incomplete class type "struct punto" is not allowed
I'm trying to create a code that creates a list of points. I have a file named "punti.c" with its header and a file named "item.c" with its header. The problem is that I can't ...
-1
votes
2
answers
49
views
Can you explain the what, how and why of the following "C" typedef struct code [closed]
Here is some sample typedef struct
typedef struct _person {
int age;
float weight;
int test;
} person;
int main()
{
person *personPtr, person1;
personPtr = &person1;
...
-1
votes
1
answer
95
views
Using typedef to shorten typename of non-nested member class of template class in C++
EDIT: Some people suggest that this is a duplicate of this question. This is NOT the case as that question is about "How to use a nested struct/class type as a return value, in a template class&...
0
votes
0
answers
48
views
vmd-1.9.4a57 compile error: typedef redefinition with different types ('void' vs 'struct Tcl_Interp') - typedef void Tcl_Interp;
I'm compiling vmd-1.9.4a57 on macos 12 (ventura) but can't get rid of this problem:
Compiling colvarproxy_vmd.C --> colvarproxy_vmd.o ...
clang: warning: argument unused during compilation: '-L/...
-2
votes
1
answer
89
views
Which is better in C or even C++? [closed]
I mean, what is better, or is there actually a difference?
typedef struct MyStruct {...} SomeName; // this one?
typedef struct {...} SomeName // or this one
And also does it depend if I use ...
0
votes
0
answers
45
views
Error Error while processingC/C++(clang-diagnostic-error) stddef.h(216, 23)
i got this error , plese anybody tell how to solve this , here is the screen
i dont know how to solve this plese any help me out of this
0
votes
1
answer
187
views
'type cast': cannot convert from 'T' to 'const char *'
This is the relevant part of the code. It doesn't allow me to assign t to my arrayStringVal array:
#include <iostream>
#include <type_traits>
char arrayStringVal[6][20];
#define printf ...
0
votes
1
answer
104
views
Is there a way to declare cyclic type aliases in C++
I have a piece of code that looks something like
class Something {};
using MyUnionType = std::variant<A, B>;
using A = Something;
using B = std::vector<MyUnionType>;
but this does not ...
0
votes
1
answer
53
views
Using a struct defined in a header file in different source (.c) files
I have a program which has several files as follows: main.c, functions.c, functions.h, matrix.c, matrix.h.
main.c is the main file. Inside functions.c there is a function which uses the struct matrix ...
0
votes
1
answer
63
views
Importing numeric C typedef into Cython automatically
Say you have a config.h" header defining a numeric type with typedef as
//config.h
typedef int32_t DTYPE_t;
or alternatively via a #define clause such as:
//config.h
#define int32_t DTYPE_t
You ...
0
votes
0
answers
38
views
dart:mirrors reflectType() not returning TypedefMirror
I am running the following dart code:
import 'dart:mirrors';
typedef Func();
void main() {
final m = reflectType(Func);
print(m);
}
I would expect m to be a reference to TypedefMirror but ...
0
votes
1
answer
516
views
In C#, how to name the type of a tuple with named members? (Like C++ typedef) [duplicate]
this question is not a duplicate of Better naming in Tuple classes than "Item1", "Item2"
In the linked Question, they ask about assigning names to tuple elements.
I am asking about ...
1
vote
1
answer
45
views
Can you effectively typedef a forward-declared class from a C++ header in the implementation file?
In C++ I want to have an implementation-specific class declared in my header like so:
// .h header file
class MyHiddenClass;
void doSomething(MyHiddenClass* data);
Then in my implementation file I ...
-1
votes
1
answer
105
views
CS50 week 4, "Recover problem", issue with memory leak
your textI actually, after a lot of sweating, finished the "recover" problem of the cs50 course. The last error I was getting was a memory leak and although I fixed it I still do not ...
0
votes
2
answers
96
views
trying to declare a pointer to a typedef structure in C
converting some python code to C. 'just' want to declare a typedef structure and a pointer to it... this is segfaulting at printf( "byte order %p\n", info->byte_order);
How is this ...
-1
votes
3
answers
130
views
Typedef shares object alias locally but not globally however at tag may share it locally or globally if not synonymous with typedefed, why?
Here is a sketch of the issue (with the error codes clang is throwing out):
Typedef and struct def of tag;
typedef struct tag {int tag;} tag;
This works just fine:
struct tag {int tag;} tag;
whereas ...
0
votes
0
answers
48
views
Ignored attributes while defining a type for intrinsic function template wrapper
I'm writing a header which makes use of templates to eliminate code duplication while implementing SIMD-based loops using intrinsics. Here's an example that hopefully makes my intention clear:
#...
0
votes
1
answer
674
views
incomplete definition of type struct & forward declaration of 'struct ElementoDiLista
When I try to compile this small snippet of code I get the following errors:
./main.c:25:8: error: incomplete definition of type 'struct ElementoDiLista'
lista->info=10;
~~~~~^
./main.c:12:16: ...
-1
votes
1
answer
71
views
Problems with typedef struct name [duplicate]
Snippet 1:
typedef struct list_s {
int key;
struct list_s *next;
}list_t;
Snippet 2:
typedef struct list_s list_t;
struct list_s {
int key;
list_t *next;
};
I don't understand in ...
1
vote
1
answer
50
views
Function pointer and struct self inclusion [duplicate]
I need the following construct:
// Header file
typedef fc_t (*comdevCbackIsReady_t)(const comdev_t* const module);
typedef struct
{
comdevCbackIsReady_t cbIsReady;
} comdev_t;
This wont ...