Skip to content

Fix x86_64 ABI calling convention for structs with floats #105

@touchft

Description

@touchft

@krrutkow I try to follow your instruction, but I get a problem. Please give a help ^_^.

testc.h file:

typedef struct
{
    float x;
    float y;
} complexx;

extern int add(int i, int j);
extern complexx op(complexx x);
extern complexx opp(complexx* x);

testc.c file:

#include "testc.h"

int add(int i, int j)
{
    int t;
    t = i + j;
    return t;
}

complexx opp(complexx* x)
{
    complexx t;
    t.x = x->x+1;
    t.y = x->y+1;    
    return t;
}

complexx op(complexx x)
{
    complexx t;
    t.x = x.x+1;
    t.y = x.y+1;    
    return t;
}

Julia code:

using CBinding
incdir =  dirname(@__DIR__) * "/src_c"
libdir =  dirname(@__DIR__) * "/src_c"
libname = "testc"
c`-I$(incdir) -L$(libdir) -l$(libname)`

c"""
    #include "testc.h"
"""j

Julia REPL:

julia> add(Cint(1),Cint(2))
3

julia> a = complexx(x=2,y=3)
var"(c\"complexx\")" (8-byte struct)
  x = 2.0f0
  y = 3.0f0

julia> op(a)
var"(c\"complexx\")" (8-byte struct)
  x = 1.0f0
  y = 1.0f0

julia> opp(Ref(a))
var"(c\"complexx\")" (8-byte struct)
  x = 3.0f0
  y = 4.0f0

Obviously, function 'op' does not works as expected. What's wrong with my code? Thank you!

Originally posted by @touchft in #103 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions