prototypes for passing custom types

This is a discussion on prototypes for passing custom types within the C Programming forums, part of the General Programming Boards category; i have a function that accepts a custom type as an input, but when i prototyped it eg: void myfunction(mytype); ...

  1. #1
    Unregistered
    Guest

    Question prototypes for passing custom types

    i have a function that accepts a custom type as an input, but when i prototyped it eg: void myfunction(mytype); i get Error: parameter list is out of context, however c++ will compile it like this, i have another function that accepts both my custom type and an int, but if i include the int in the prototype c++ gives the error 'int ' : prototype parameter in name list illegal, without it will c compile under c++, my other c compiler Digital Mars C compiler gives error with both,

    anyone got any ideas??

    thanks in advance

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Trying to understand your post, it sounds like you're using a struct or something similar. Here's the thing, C and C++ are not the same, they never will be. For example:
    Code:
    struct name{
      /* Data members */
    };
    .
    .
    .
    void function ( name t ); /* Works with C++, not with C */
    void function ( struct name t ); /* Works with C and C++ */
    C requires the use of the struct tag while C++ makes it optional. Such is the way with user defined types, if your type is a struct then add the struct keyword wherever you instance it and it should compile. Another way is to typedef the struct and use the typedef'd name:
    Code:
    typedef struct name{
      /* Data members */
    } NAME;
    .
    .
    .
    void function ( NAME t ); /* Works with C and C++ */
    -Prelude
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest

    Post

    i have done it the 2nd way with the typedef, and i get the errors defined above, i am writing it all in c, but using the visual c++ compiler/ide then compiling it with my other c compiler

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Please post some code then

    -Prelude
    My best code is written with the delete key.

  5. #5
    Unregistered
    Guest

    Red face

    i solved it, i keep all the prototypes in a separte header file, and i was including that before i created my typedef structure, so it wasent recognising it,

    thanks for ur help anyway

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Custom variable types in C++
    By Aeroren in forum C++ Programming
    Replies: 2
    Last Post: 07-06-2005, 10:07 AM
  4. Clipboard and Custom Types
    By McClamm in forum C# Programming
    Replies: 1
    Last Post: 09-16-2004, 04:43 PM
  5. Custom File Types
    By Misled Hacker in forum Game Programming
    Replies: 6
    Last Post: 11-07-2002, 06:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21