type-conversion in one function in C

hadolfo

I have one doubt, could it be possible to create one

typedef struct whatever

and then if one function requires:

void function(char * something);

when you call the function in main program write:

function((char *) whatever);

is that correct?

Thank you!

John Bollinger

There is no defined behavior for casting a structure to any pointer type. Very likely your compiler would reject such a cast, but if it accepted it then the resulting behavior is unlikely to be useful.

Moreover, you cannot pass a type (i.e. whatever) as a function argument.

You could conceivably pass a pointer to an object of your type:

int main() {
    whatever my_whatever = { 0 };
    function((char *) &my_whatever);
}

That will work, for some definition of "work". Whether it is sensible depends on the implementation of function().

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

interface{} to function type conversion

From Dev

Implicit conversion of function type

From Dev

implicit conversion of vector from one type to another c++

From Dev

C++ Weird Type Conversion Error wtih Function Template

From Dev

C++ Weird Type Conversion Error wtih Function Template

From Dev

Type conversion in C++

From Dev

Type conversion confusion in C

From Dev

C to Pascal type conversion

From Dev

c language type conversion

From Dev

Type conversion in c

From Dev

std::function implicit type conversion

From Dev

Type conversion iterator in C++

From Dev

Explicit type conversion in c language

From Dev

Implicit integer type conversion in C

From Dev

confused by C# type conversion

From Dev

C++ Type conversion error /

From Dev

Type conversion c++, quadmath

From Dev

C# - Return type of a function is the same a the one of a parameter

From Dev

Why is my hex conversion function off by one?

From Dev

what is the standard way to do conversion based on the required type in a template function in c++

From Dev

Narrowing conversion from 'long' to signed type 'char' is implementation-defined (strtol function in C)

From Dev

groovy implicit function parameter type conversion

From Dev

Why is this function overload with argument type conversion ambiguous?

From Dev

Scala weird behavior for type conversion in generic function

From Dev

Custom function in Access is returning type conversion error

From Dev

Why is this function overload with argument type conversion ambiguous?

From Dev

Data Conversion from one class type to another class type

From Dev

C# type conversion: Explicit cast exists but throws a conversion error?

From Dev

C# type conversion: Explicit cast exists but throws a conversion error?

Related Related

  1. 1

    interface{} to function type conversion

  2. 2

    Implicit conversion of function type

  3. 3

    implicit conversion of vector from one type to another c++

  4. 4

    C++ Weird Type Conversion Error wtih Function Template

  5. 5

    C++ Weird Type Conversion Error wtih Function Template

  6. 6

    Type conversion in C++

  7. 7

    Type conversion confusion in C

  8. 8

    C to Pascal type conversion

  9. 9

    c language type conversion

  10. 10

    Type conversion in c

  11. 11

    std::function implicit type conversion

  12. 12

    Type conversion iterator in C++

  13. 13

    Explicit type conversion in c language

  14. 14

    Implicit integer type conversion in C

  15. 15

    confused by C# type conversion

  16. 16

    C++ Type conversion error /

  17. 17

    Type conversion c++, quadmath

  18. 18

    C# - Return type of a function is the same a the one of a parameter

  19. 19

    Why is my hex conversion function off by one?

  20. 20

    what is the standard way to do conversion based on the required type in a template function in c++

  21. 21

    Narrowing conversion from 'long' to signed type 'char' is implementation-defined (strtol function in C)

  22. 22

    groovy implicit function parameter type conversion

  23. 23

    Why is this function overload with argument type conversion ambiguous?

  24. 24

    Scala weird behavior for type conversion in generic function

  25. 25

    Custom function in Access is returning type conversion error

  26. 26

    Why is this function overload with argument type conversion ambiguous?

  27. 27

    Data Conversion from one class type to another class type

  28. 28

    C# type conversion: Explicit cast exists but throws a conversion error?

  29. 29

    C# type conversion: Explicit cast exists but throws a conversion error?

HotTag

Archive