Git Product home page Git Product logo

Comments (8)

snej avatar snej commented on July 24, 2024

This is weird. It’s true that a bool can hold values other than 0 or 1, but in general it shouldn’t, as it only gets initialized by the constants true or false, or by a logical operation like &&.

The values you’re seeing make me suspect something’s wrong. Where did that c4options struct come from? I suspect it may have been allocated/declared without getting initialized, so the fields contain garbage…

from cbforest.

borrrden avatar borrrden commented on July 24, 2024

The portion of the test I noticed this in was here:

C4AllDocsOptions options = kC4DefaultAllDocsOptions;
options.includeBodies = false;
e = c4db_enumerateAllDocs(db, kC4SliceNull, kC4SliceNull, &options, &error);

from cbforest.

snej avatar snej commented on July 24, 2024

In that case kC4DefaultAllDocsOptions must not be initialized properly … the bools in there should all be 1 or 0. Is MSVC leaving the fields unmentioned in the initializer as garbage?

from cbforest.

borrrden avatar borrrden commented on July 24, 2024

I have it setup with the C position-based struct initializer (see https://github.com/couchbaselabs/cbforest/blob/feature/c_api/C/c4Database.cc#L611-L618). I don't quite know what is going on with that. I could try using (bool)1 I guess. I'm almost sure it is some weird compiler optimization because the C# bindings don't have this problem (You can't bind to a variable in C# so the defaults, etc, are all redefined in C#)

from cbforest.

snej avatar snej commented on July 24, 2024

Could you set a breakpoint and examine the contents of the struct to see if they're garbage? They shouldn't be, from what I know of the C standard, but it's possible this is a quirk of MSVC…

from cbforest.

borrrden avatar borrrden commented on July 24, 2024

I already did that, it's how I found the values I noted in the original ticket. The contents of the struct are weird. The variable examiner will show things like "true (233)" I wonder which standard is being applied here, because bool is a C99 thing and we all know how MSVC fares with C99. However, it is also a C++ thing. Everything I look at says "this shouldn't happen" which frustrates me.

from cbforest.

snej avatar snej commented on July 24, 2024

This shouldn't happen. :/ It's in C++ code so there's no problem with bool, and you're explicitly initializing every field of the struct to a valid value. If the fields don't have those values at runtime, it seems like the compiler screwed up.

from cbforest.

borrrden avatar borrrden commented on July 24, 2024

I've found another clue in this matter. It seems like ANY global const struct getting exported for use in CppTests is getting completely blown away for some reason with Visual Studio. Everything inside of it is garbage. This garbage just happened to be closer to the truth than the garbage I am dealing with now.

from cbforest.

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.