|
more like dICK posted:Are there any good JSON libs for C? Jansson?
|
# ? Sep 15, 2013 04:19 |
|
|
# ? Jun 8, 2024 09:02 |
|
more like dICK posted:Are there any good JSON libs for C? I've used https://github.com/json-c/json-c before and didn't mind it. But it was for some simple hobby stuff.
|
# ? Sep 15, 2013 05:34 |
|
more like dICK posted:Are there any good JSON libs for C? I can second jansson.
|
# ? Sep 15, 2013 16:15 |
|
I'm writing a program that dumps a shitload of logs for each run. Something on the order of a gig or two uncompressed. Is there a simple way to compress that on-the-fly? I'm currently just using your basic FILE * and fprintf line printing. Is there some way I could make the underlying stream compress to gzip or something? I'm in a POSIX environment but don't have admin access, is there a way to make a FUSE-type mount point into a compressed filesystem somewhere? Basically I want to pipe through gzip and then to disk, but with a couple different streams instead of just stdout, or something along that line. e: looks like Zlib should fit the bill Paul MaudDib fucked around with this message at 23:48 on Sep 16, 2013 |
# ? Sep 16, 2013 23:44 |
|
One option is setting up named pipes: http://en.wikipedia.org/wiki/Named_pipe
|
# ? Sep 17, 2013 00:13 |
|
more like dICK posted:Are there any good JSON libs for C? Related, what would you recommend for a C++ library? I've been using Qt's JSON functionality since almost all my C++ projects use Qt anyway, but I'm interested in decent alternatives for things that don't need a UI.
|
# ? Sep 17, 2013 04:50 |
|
I haven't taken more than a cursory glance at it, but it seems like yajl has its head together reasonably well.
|
# ? Sep 17, 2013 12:33 |
|
We currently have a large codebase. Tons of products that all use a bunch of small components. They are referenced using SVN externals. This is a bitch to maintain since all management of externals, such as upgrading to a newer version, is completely manual. This works, but it would be much nicer to have a model similar to npm in NodeJS land where you create a "package.json" file containing your dependencies, the semantic version of said dependencies (e.g. "1.0", "1.2.*", "latest", etc). It allows you to specify whether dependency is an actual dependency or a dependency that is used during development (e.g. CppUnit). It allows you to easily update all dependencies to the latest matching semantic version as well. Is there something like that for C/C++ that would also allow you to specify whether you'd fetch the dependency as binary or as source. Cross-platform too, of course. Options I've considered so far: * CMake - That's geared more towards cross-platform project setup, builds, and so on. * Apache Ivy - Seems more related to Java, but *should* in theory also work for other languages. Seems generally scary due to verbose XML config. * Ryppl - Seems nice, but is also completely abandoned. TL;DR: Are there any good dependency management systems available for C/C++ that are simple to use?
|
# ? Sep 17, 2013 14:43 |
|
The best json library for c is wjelement. https://github.com/netmail-open/wjelement. Seriously, it's the poo poo. They implemented xpath style access to json elements and support for json-schema. Check out the example here: https://github.com/netmail-open/wjelement/wiki/WJElement-Example
Dren fucked around with this message at 18:43 on Sep 17, 2013 |
# ? Sep 17, 2013 18:35 |
|
I'm trying to play around with threading, and getting a 'program has triggered a breakpoint' that isn't very explanatory...code:
This doesn't help me, but maybe it will help someone else explain to me what I've done wrong... When I replace the ProcessImage function with a simple function that cout's an integer, no errors. I've never had a problem with the processimage function outside of this threading example though. bobua fucked around with this message at 03:13 on Sep 18, 2013 |
# ? Sep 18, 2013 01:20 |
|
Is there a site listing clever collection manipulation tricks with Boost or even just STL? I've recently had to do some stuff with vectors like check if there's at least one element in one that matches some rules. I would have liked to use a lambda as a predicate function, but I couldn't figure out how to make one out of a series of compound statements. I've also wanted to create a sum from a particular field of each element in a container. It gets tedious to write the for-loops, and hides what I'm trying to do when I know the goal when I'm writing all this container examination code.
|
# ? Sep 18, 2013 19:31 |
|
Rocko Bonaparte posted:Is there a site listing clever collection manipulation tricks with Boost or even just STL? I've recently had to do some stuff with vectors like check if there's at least one element in one that matches some rules. I would have liked to use a lambda as a predicate function, but I couldn't figure out how to make one out of a series of compound statements. I've also wanted to create a sum from a particular field of each element in a container. It gets tedious to write the for-loops, and hides what I'm trying to do when I know the goal when I'm writing all this container examination code. Your first example can be done using C++11 std::any_of. code:
code:
|
# ? Sep 19, 2013 01:46 |
|
Another dumb aliasing question: How does it work with struct members, or is that also undefined? i.e. if I do this: code:
|
# ? Sep 19, 2013 02:46 |
|
Pretty much everything involving reinterpret_cast other than casting a void pointer back to its original type is undefined behavior.
|
# ? Sep 19, 2013 02:53 |
|
I think that's specifically allowed to enable that pattern where you bunch all those structs into a union and use the first field to figure out what to cast them to. Edit: I guess you actually have to put them into a union for that to apply. quote:If a standard-layout union contains two or more standard-layout structs that share a common initial sequence, and if the standard-layout union object currently contains one of these standard-layout structs, it is permitted to inspect the common initial part of any of them. Two standard-layout structs share a common initial sequence if corresponding members have layout-compatible types and either neither member is a bit-field or both are bit-fields with the same width for a sequence of one or more initial members. Vanadium fucked around with this message at 02:58 on Sep 19, 2013 |
# ? Sep 19, 2013 02:54 |
|
Although it's not technically portable, I've never worked on a system where it didn't work as long as you're careful with alignment. For example it's not unusual to load data by reading in raw bytes from disk and just casting to whatever structure, perhaps with a subsequent pointer patching pass.
|
# ? Sep 19, 2013 09:04 |
|
You're just inviting the next release of clang to see what you're doing and go "that's clearly undefined so i can optimize it by deleting your code".
|
# ? Sep 19, 2013 12:50 |
|
Plorkyeran posted:Pretty much everything involving reinterpret_cast other than casting a void pointer back to its original type is undefined behavior. That's static_cast. This is a legal use of reinterpret_cast. As for structure layouts: you cannot portably define the exact memory layout of a structure, but you can ensure your program doesn't compile if your assumptions don't hold: use static_assert with offsetof and is_same to ensure that the offset and type of the two fields is the same. Something like this: code:
hackbunny fucked around with this message at 13:32 on Sep 19, 2013 |
# ? Sep 19, 2013 13:30 |
|
At least in C you know the structure layouts will be the same in common prefixes of structures. Or at least when they make appearances in unions or something.
|
# ? Sep 20, 2013 05:24 |
|
hackbunny posted:E: might want to ensure StructA and StructB are both PODs, too
|
# ? Sep 20, 2013 11:01 |
|
hackbunny posted:That's static_cast. This is a legal use of reinterpret_cast. The reinterpret_cast is legal. The access to an object whose dynamic type doesn't match the static type you're accessing it as isn't. An access to a field is simultaneously an access to the enclosing object for the purposes of this rule, or at least that's the interpretation taken by both Clang and GCC. What exactly happens with unions is something of a point of debate, which is part of why Clang implements this so as to not miscompile obvious cases of illegal aliasing.
|
# ? Sep 21, 2013 22:05 |
|
Not quite sure how to google this and get the exact answer... If I have the following layout... foo.h --- class foo {... foo.cpp --- int my_var = 3; Is foo a static global variable? I had been assuming it was just a global that would always start out at 3 with each instance of the class, but after playing with some threading and multiple instances, it didn't quite behave that way. To be a little more specific, I was actually using a vector and was getting a vector iterator error that I tracked down to that variable, after putting it in the header file the problem went away. edit: to be clear, the header file has no mention of my_var bobua fucked around with this message at 02:42 on Sep 22, 2013 |
# ? Sep 22, 2013 02:38 |
If your my_var is not a member of the class, and is not a local variable in a function, then it's a true global. There will be a single instance of it for the entire program. More specifically. This: C++ code:
Now this: C++ code:
Lastly, this: C++ code:
Note how in the .cpp file the variable's declaration is prefixed with the class' name, and in the class declaration in the .h file it's declared as static. The difference is that in the first example, the variable has absolutely zero relation to the class. It happens to be defined in the same source file that implements a function in the class, but that's not relevant. In the first example, the variable is not declared inside the class so it has no relation to it.
|
|
# ? Sep 22, 2013 03:08 |
|
The real-world application was an attempt to alias handle containers with compatible members. It sounds like it can't be done though, and if I'm one annoyance away from just going to -fno-strict-aliasing given that this is quickly becoming insufferable for low-level code and most of the advantages are easier to get by just aggressively pulling things into local vars than trying to guess when the optimizer will gently caress my code.
OneEightHundred fucked around with this message at 04:13 on Sep 22, 2013 |
# ? Sep 22, 2013 04:07 |
|
What's the state of Clang on win32 these days particularly when it comes to it's standard library? I understand the library isn't finished being ported yet, can I substitute out the one in Visual Studio 2012 or 2013 when it comes out to have a mostly up to date C++11 library? This is for porting something that already runs under Linux/OS X to Windows.
|
# ? Sep 22, 2013 14:50 |
|
OneEightHundred posted:The real-world application was an attempt to alias handle containers with compatible members. It sounds like it can't be done though, and if I'm one annoyance away from just going to -fno-strict-aliasing given that this is quickly becoming insufferable for low-level code and most of the advantages are easier to get by just aggressively pulling things into local vars than trying to guess when the optimizer will gently caress my code. Putting them all into a union doesn't work?
|
# ? Sep 22, 2013 15:56 |
|
nielsm posted:
Thanks for taking the time to spell that out, it explained it all perfectly. Separate question, is there a de-facto library for getting fancy in the windows console? I don't really know exactly what I want to do, it's just kind of random when I'm playing with things, but I was curious if there was a go-to option instead of just googling for a bit of hackery every time I want to do something more than changing the text color. bobua fucked around with this message at 19:28 on Sep 22, 2013 |
# ? Sep 22, 2013 19:16 |
|
Vanadium posted:Putting them all into a union doesn't work? Worse still, I'm pretty sure using unions to alias is also non-standard behavior that some compilers will ignore (i.e. Sun CC), it just happens to be allowed by GCC despite other statically-provable aliasing (i.e. local vars) being ignored for some reason.
|
# ? Sep 22, 2013 19:36 |
|
9.3 p19 posted:If a standard-layout union contains two or more standard-layout structs that share a common initial sequence, and if the standard layout union object currently contains one of these standard-layout structs, it is permitted to inspect the common initial part of any of them. Two standard-layout structs share a common initial sequence if corresponding members have layout-compatible types and either neither member is a bit-field or both are bit-fields with the same width for a sequence of one or more initial members. Guess it doesn't help for your fancy objects.
|
# ? Sep 22, 2013 20:45 |
|
OneEightHundred posted:non-standard behavior that some compilers will ignore (i.e. Sun CC) Do people still willingly use sun cc? I haven't used it in years and years but I remember it being total poo poo.
|
# ? Sep 22, 2013 20:52 |
|
Willingly? No.
|
# ? Sep 22, 2013 20:54 |
|
Supposedly VS 2013 RC added some C99 support and has additional C++ 11 support. I still think its lovely that they aren't adding the additional C++ 11 support into 2012 edition.
|
# ? Sep 22, 2013 21:06 |
|
fritz posted:Do people still willingly use sun cc? What they really need to do is just make may_alias standard (or make another memory model template for it like they did with std::atomic). char being the only guaranteed aliasable type is really stupid. OneEightHundred fucked around with this message at 21:55 on Sep 22, 2013 |
# ? Sep 22, 2013 21:52 |
|
I had to build some apps the other day on Solaris 10 SPARC with Sun CC, lol, Sunfreeware.com is no longer free.
|
# ? Sep 22, 2013 21:56 |
|
Hughlander posted:What's the state of Clang on win32 these days particularly when it comes to it's standard library? I understand the library isn't finished being ported yet, can I substitute out the one in Visual Studio 2012 or 2013 when it comes out to have a mostly up to date C++11 library? This is for porting something that already runs under Linux/OS X to Windows. They're working on a LLVM for windows installer at the moment: http://llvm.org/builds/ However it's not entirely able to use all of Microsoft's standard library (for instance you can't use any <*stream> headers). If you're porting something to Windows from Linux/OS X, I'd recommend using the MinGW-builds 4.8.1 SEH POSIX version. It implements all of the standard, uses SEH for exception handling, and the all of the std::future stuff actually works (it currently doesn't with MinGW Win32 threads builds, or at least it didn't in 4.8.0 and I didn't see any changes related to that in 4.8.1) I've yet to run into a compatibility issue with it when moving from clang to mingw and back, outside of perhaps libstdc++ missing one or two constructors within container classes (specifically allocator.uses.construction)
|
# ? Sep 23, 2013 01:08 |
|
I'm having some trouble setting up a struct within a class. I've asked about it on Stack Overflow here, but my problem hasn't been resolved. Does anyone here have any insight?
|
# ? Sep 23, 2013 13:24 |
hooah posted:I'm having some trouble setting up a struct within a class. I've asked about it on Stack Overflow here, but my problem hasn't been resolved. Does anyone here have any insight? Yeah that's some pretty bad code and a question not showing much effort put into solving it yourself. No wonder it's been downvoted. You could start with writing a function that works on a vector of structures, and finds a structure in the vector where a specific field has a given value. Then explain in this thread how that function relates to your problem at hand.
|
|
# ? Sep 23, 2013 13:32 |
|
Well, I'm kind of groping in the dark since I'm beyond what I've learned in class so far, so bad code shouldn't be that surprising. I did try to solve it myself, but there weren't any results when I searched for the error, and sticking a semicolon in spots that seemed they might be appropriate didn't change anything. I've done as you suggested, but it isn't going well. Here is my testing program: code:
code:
(e.g. the error with '<<', missing identifier before 'name'), I don't understand why it's complaining.
|
# ? Sep 23, 2013 14:51 |
|
1. Don't use the "just add semicolons" approach to debugging. I totally get why new people do that - C++'s semicolon rules aren't the most intuitive - but it will get you nowhere in the long run. 2. Before you use a class or a struct, you have to declare, and possibly define, it (depending on how you're using it). Your definition of findname tries to use grades, but the compiler doesn't know about grades yet. Move the struct definition to before the function definition. 3. cout name is invalid C++ syntax. Any time you see word otherword (that I can think of) you've done something wrong. That snippet should be cout << name. 4. Function definitions don't end with a semicolon. 5. main should return something (0 in this case). Also, the following aren't causing compilation problems, but are worth pointing out: 6. All your struct's members are public (because they're public by default, because it's a struct), but you've also provided accessors for them, which is redundant and confusing. You should either make the data members private, change the struct to a class (which would require making the member functions public), or remove the accessors. 7. When you define a member function inside a class/struct definition, you don't need to qualify it (e.g. grades::add_grade versus just add_grade). 8. grades student_1 = grades("Ben"); can be written grades student_1("Ben");.
|
# ? Sep 23, 2013 15:10 |
|
|
# ? Jun 8, 2024 09:02 |
|
Thanks for your helpful reply. 3 and 4 I really should have caught myself. I removed the accessor for the struct and removed the scope operator in the member function. Now my question is how do I access the public data members? Specifically, in the cout statement, how do I access an element in a vector within the struct?
|
# ? Sep 23, 2013 15:28 |