Coder Social home page Coder Social logo

Compiler errors about mlib HOT 3 CLOSED

jacknicklenson avatar jacknicklenson commented on May 28, 2024
Compiler errors

from mlib.

Comments (3)

jacknicklenson avatar jacknicklenson commented on May 28, 2024

Okey now i get it why it is not work i have to define :

_Bool cmp(node_s n1, node_s n2) {
  return (n1.w == n2.w && n1.h == n2.h);
}

ARRAY_DEF(arr_node, node_s, (CMP(cmp)))

to know how to compare two custom data. thx anyway :)

from mlib.

P-p-H-d avatar P-p-H-d commented on May 28, 2024

By default, ARRAY_DEF expects to work on integer/float types, whereas a struct is used. Some operations are not possible on structures in C. So, the solution is to give the oplist responsible to handle POD struct to ARRAY_DEF:

ARRAY_DEF(arr_node, node_s, M_POD_OPLIST)

This will use the C function memcmp to compare your structure.
Alternatively, you can also register globally the oplist of your node by defining the macro M_OPL_node_s:

#define M_OPL_node_s() M_POD_OPLIST
ARRAY_DEF(arr_node, node_s)

This generates the same code.

_Bool cmp(node_s n1, node_s n2) {
  return (n1.w == n2.w && n1.h == n2.h);
}
ARRAY_DEF(arr_node, node_s, (CMP(cmp)))

There is an issue with this solution: the provided function is a matching method for the EQUAL operator, not for the CMP operator. The CMP operator expects a total order of the elements, like this:

int cmp(node_s n1, node_s n2) {
  return (n1.w < n2.w ? -1 : n1.w > n2.w ? 1 : n1.h < n2.h ? -1 : n1.h > n2.h);
}
ARRAY_DEF(arr_node, node_s, (CMP(cmp)))

from mlib.

jacknicklenson avatar jacknicklenson commented on May 28, 2024

hmmm very nice explanation,i see right now, thank you very much! :)

from mlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.