#568 function pointer and pointer arguments

closed-rejected
None
5
2013-05-25
2003-08-12
Anonymous
No

Hello, in some cases the compiler has problems passing
an pointer argument to a function if the function is
called by a pointer.

the error says, that these types are incompatible, but
i dont't see why they should be.

SDCC : ds390/TININative/ds400 2.3.5 (Aug 12 2003) (UNIX)

test2.c:50: error: incompatible types
from type 'struct partition_t xdata-xdata* '
to type 'struct partition_t xdata* '

Discussion

  • Nobody/Anonymous

    code to reproduce error

     
  • Erik Petrich

    Erik Petrich - 2004-01-13

    Logged In: YES
    user_id=635249

    This is an error in how the data structures are declared.
    Here's the problematic part of the code:

    struct fs_interface_t {
    char (*check_fs)(struct partition_t xdata*) reentrant;
    };

    struct partition_t {
    struct drive_interface_t xdata *di;
    struct fs_interface_t xdata *fs;
    ulong start_sector;
    ulong size;
    uint sector_size;
    };

    When the "struct partition_t xdata*" declaration in the
    check_fs function is encountered, there is no struct
    partition_t type defined yet. Thus it is created in the
    current scope: the parameter declarations of the check_fs
    function. As soon as the compiler leaves this scope, all of
    the definitions that are no longer in scope, including this
    one, are discarded.

    When the "struct partition_t" declaration in the top level
    scope is encountered, there is again no struct partition_t
    type defined and so it becomes the new definition. The
    compiler never leaves the top level scope, so this struct
    definition is retained for the remainder of the program.

    Thus the compiler is entirely correct to complain that the
    formal and actual parameters are incompatible, because they
    are based on different struct type definitions. The error
    message does not reflect this problem because both structs
    have been given the same name. To make this work as
    intended, a forward declaration of the struct type is needed
    before any other usage:

    struct partition_t;

    With this in place, any following struct partition_t
    declaraction will bind back to this declaration. Hence,
    there will only be one struct type with this name and no
    incompatibility will arise.

     
  • Erik Petrich

    Erik Petrich - 2004-01-13
    • assigned_to: nobody --> epetrich
    • milestone: --> non_bugs
    • status: open --> closed-rejected
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks