|
The Gay Bean posted:I think I'm just going to start making Cmake compile all of my dependencies with specific flags and git/svn versions.. would anybody hate me if I were their coworker? You might be okay if you include downloading in your automated setup though. But even then, getting a specific version kind of sucks because usually a newer version with the same flags will do the trick, so ideally what you want is an automatic download of the newest version, and build with specific flags. Kind of like a packaging system, but less broken. (And then you want a fallback to the last known working version if the build doesn't work.)
|
# ? Nov 3, 2014 15:39 |
|
|
# ? May 14, 2024 21:08 |
|
The Gay Bean posted:I think I'm just going to start making Cmake compile all of my dependencies with specific flags and git/svn versions.. would anybody hate me if I were their coworker? No. In fact, we have deployed the same system where I work. We used to check in precompiled binaries for the external dependencies we use, but it becomes such a chore to maintain. New compiler or new version of the library? Sure, let's find whoever compiled the library to begin with and see if they remember if they did anything special before they compiled and committed the lib. Nowadays we use CMakes ExternalProject_Add. It works decently, the first time you build from source it will compile all external dependencies. Then it won't do so until you either change something or remove your build output directory(even if you use "Full rebuild" in Visual Studio). It works well with CI tools, since they can remove build directories during nightly builds, guaranteeing that you can always build from source but still costing no time for devs. The command even has support for downloads, so you could have a branch that is always up to date to see if new versions break your build. It also has support for custom commands for configure/build/install, which lets you compile libraries the way the developers want you to. The downside is, of course, that it's a CMake function and the syntax for using it is horrible.
|
# ? Nov 3, 2014 17:36 |
|
Stupid embedded question that's kicking my rear end on a lab assignment with a TI Launchpad. (MSP430G2553) I know this isn't the homework help forum, but i figured it was worth a shot to get a fresh perspective on this... The problem is to read from a temperature sensor (TMP36GZ) and turn on an LED on port 1.5 when the temperature rises above 2 degrees Fahrenheit from the temperature recorded at startup. Conversion to Fahrenheit needs to be done by calling a function. The TA's in charge of the lab already wrote the setup for the 10 bit ADC, we just have to fill in the rest. I cannot for the life of me get this to do anything other than sit there with the LED shining with no way to change it. I verified all of the wiring so it has to be a code problem. code:
Lean Six Ligma fucked around with this message at 03:51 on Nov 6, 2014 |
# ? Nov 6, 2014 02:51 |
|
Pixelated posted:What am I missing? Try running a simple program that sets and unsets BIT5 on P1OUT and see what happens.
|
# ? Nov 6, 2014 11:51 |
|
code:
|
# ? Nov 6, 2014 17:37 |
|
TheFreshmanWIT posted:
Assuming his macros work correctly that should set bit5 on p1out to 1 whenever tempF < initTemp. |= doesn't make it cycle between 1 and 0. Whether bit5 is supposed to be a 1 or a 0 to turn the on the led is unclear.
|
# ? Nov 6, 2014 17:50 |
|
It needs to be a 1 to turn the LED on. The first thing I did after breadboarding the little circuit was make a program to make the three LEDs sweep back and forth like KITT/cylon Also holding a hot soldering iron near the sensor didn't turn the LED off, so even if I have it backwards, i'm not sure what's going on... Lean Six Ligma fucked around with this message at 18:17 on Nov 6, 2014 |
# ? Nov 6, 2014 18:14 |
|
Pixelated posted:It needs to be a 1 to turn the LED on. C++ code:
|
# ? Nov 6, 2014 18:56 |
|
Switching the if-else around made it work perfectly. not sure what was going on there or how I missed that it was backwards... Fun stuff: if the laptop powering the MCU is plugged in, the switch to turn on another LED makes this one toggle rapidly. If i'm on battery, it works perfectly pretty sure that's an electronics problem, and not software, though. Works perfectly otherwise. Thanks for the help!
|
# ? Nov 6, 2014 20:58 |
|
Pixelated posted:Stupid embedded question that's kicking my rear end on a lab assignment with a TI Launchpad. (MSP430G2553) I know it sounds so simple, but are you supplying the TMP36GZ with +3.3V on it's Vcc? This formula assumes so, and if you're feeding it +5V it's going to output wrong. EDIT: Alternatively consider posting in the Embedded Systems Megathread. Mellow_ fucked around with this message at 22:45 on Nov 6, 2014 |
# ? Nov 6, 2014 22:38 |
|
Does anybody know of a library where you can open multiple streams for input and output inside of a compressed archive? The idea would be an archive format for which a series of images and text files can be stored.. sort of like a docx file.
|
# ? Nov 7, 2014 04:22 |
|
libarchive?
|
# ? Nov 7, 2014 05:41 |
|
That should do the trick, thanks.
|
# ? Nov 7, 2014 07:54 |
|
I'm looking at a codebase that routinely calls function pointers with the wrong number of arguments. It compiles as C, but not as C++. Is there some legitimate reason for this to compile?
|
# ? Nov 8, 2014 00:03 |
|
GrumpyDoctor posted:I'm looking at a codebase that routinely calls function pointers with the wrong number of arguments. It compiles as C, but not as C++. Is there some legitimate reason for this to compile? are the function pointers of the form T()? in c a function of that form can take as many arguments as you would like to supply to it, whereas in c++ that is explicitly a function that takes no arguments. otherwise, you're gonna have to cast function pointers which means undefined behavior. i would think in that case youd be seeing runtime errors, though. EDIT: just to double check, the functions youre taking the address of arent defined with old style function declarations are they? that would definitely not compile in c++ but will compile in c given the correct flags AND will allow you to pass whatever amount of arguments you want because old style declarations are insanity FamDav fucked around with this message at 00:39 on Nov 8, 2014 |
# ? Nov 8, 2014 00:33 |
|
FamDav posted:are the function pointers of the form T()? in c a function of that form can take as many arguments as you would like to supply to it, whereas in c++ that is explicitly a function that takes no arguments. Yep, that's it. My problem is that I need to compile this as C++ and they're relying on this behavior all over the place.
|
# ? Nov 8, 2014 00:37 |
|
GrumpyDoctor posted:Yep, that's it. My problem is that I need to compile this as C++ and they're relying on this behavior all over the place. i honestly havent had to actually do this in the wild, but here's my understanding of how to get this done. i'm assuming this is a library? if so: * compile the library via your c compiler * wherever you are including headers from the c lib, wrap the macros in "extern "C" { #include "butts.h" }". this is where you find out if they were doing this in their headers :[. * compile and link the rest of your program with your c++ compiler if all goes correctly, your c code is compiled correctly, your c++ code calls into it with the correct calling conventions, and everybody ends up happy.
|
# ? Nov 8, 2014 00:48 |
|
FamDav posted:i honestly havent had to actually do this in the wild, but here's my understanding of how to get this done. i'm assuming this is a library? if so: I know how to link C and C++ code. I want to compile it as C++ so I can include it in a mixed-mode C++/CLI assembly.
|
# ? Nov 8, 2014 01:46 |
|
FamDav posted:are the function pointers of the form T()? in c a function of that form can take as many arguments as you would like to supply to it, whereas in c++ that is explicitly a function that takes no arguments. It's okay to cast function pointers to other kinds of function pointers, so long as you never call the function through a pointer of the wrong type. So when you actually want to call the function, you can cast it to the correct type just before you use it: code:
|
# ? Nov 8, 2014 12:06 |
Trying to relearn some C (my previous background in it was real basic to begin with) because my professor for my math undergrad capstone wants to use the C99 standard for part of it. I'm trying to make a C function that can take a mathematical vector function as the 3 separate components, ie: Vector-A = <Ax,Ay,Az> where each of those 3 are 3-variable mathematic functions that can get pretty complex. I don't really know though how I should handle the function inputs so that they can be parsed as a mathematical expression that calculations can be done on where x, y, z are all arrays of values. Evrart Claire fucked around with this message at 02:35 on Nov 9, 2014 |
|
# ? Nov 9, 2014 02:31 |
|
Zerilan posted:Trying to relearn some C (my previous background in it was real basic to begin with) because my professor for my math undergrad capstone wants to use the C99 standard for part of it. What is a mathematic function? So Ax, Ay, and Az are functions from R^3 to R (or C^3 to C?). Why do you need to parse them as mathematical expressions in order to evaluate them? Wouldn't they just be C functions, that take a value in R^3 (or C^3) as input and return a value in R (or C)? What is x, y, and z? You didn't mention them before you suddenly said they're arrays of values. What kind of value? Are you saying that the functions Ax, Ay, and Az would have different inputs (they being x, y, and z), because if so I think that's wrong, because they're computing components of the function "Vector-A" which means they'd all take the same input value (a point in R^3 (or C^3)). sarehu fucked around with this message at 10:43 on Nov 9, 2014 |
# ? Nov 9, 2014 10:41 |
|
FamDav posted:* wherever you are including headers from the c lib, wrap the macros in "extern "C" { #include "butts.h" }". this is where you find out if they were doing this in their headers :[. Never do this. GrumpyDoctor posted:I know how to link C and C++ code. I want to compile it as C++ so I can include it in a mixed-mode C++/CLI assembly. There's no way to get the behavior you want in C++ without source changes, but you can certainly follow this sage advice: Qwertycoatl posted:It's okay to cast function pointers to other kinds of function pointers, so long as you never call the function through a pointer of the wrong type. So when you actually want to call the function, you can cast it to the correct type just before you use it: You can write a variadic template to automate casting to the right function type, although I don't know if the C++/CLI frontend supports those. But you'll still need to modify both the original declaration and the definition to use C linkage, because parameter types distinguish functions in C++. But you will probably be happier if you just bite the bullet and bring that source base kicking and screaming into the late 1980s by using proper function prototypes. Fortunately, that should be extremely scriptable.
|
# ? Nov 9, 2014 11:01 |
Ok yeah, let me try wording that better. I need to write a function to calculate finite difference approximations in C99 to find the curl of a Vector. So I need to take a vector-valued function in R^3 (ie: Vector-A = AxI + AyJ +AzK where I,J,K are the unit vectors in the x y z dimensions, and Ax,Ay,Az are each something like "x^3*y^3+z^4" or an "r^2+r+C" polynomial where r=sqrt(x^2+y^2+z^2), plot each point of the vector using a large range of R^3 points (x,y,z since using Cartesian coords), based on a min-max range of each of them and a given spacing (ie: x from -2 to 2 with .01 spacing), and use the values generated from that to approximate the curl of the vector at each set of values. Function needs to take in the vector-valued function, or each R->R component separately, the domain of x,y,z points to calculate it at (so the max/min of x, y, and z), and the spacing between points for each of x,y,z, and output the curl of the vector at each r^3 point. Don't have any problems with doing the calculations in the function, but I don't really know how to handle the function inputs.
|
|
# ? Nov 9, 2014 11:11 |
|
Point of order: You keep saying "vector" in places where you mean "vector field". (e: And I assume by "each R->R component" you mean "each R->R^3 component".) Presumably you would have your function prototype be return_type do_curl_stuff(vec3 (*vectorA)(vec3), ...other parameters...) where vec3 is your 3 dimensional vector type, defined by something such as typedef struct { double x, y, z; } vec3; or typedef struct { double coords[3]; } vec3;. sarehu fucked around with this message at 11:29 on Nov 9, 2014 |
# ? Nov 9, 2014 11:26 |
|
GrumpyDoctor posted:I'm looking at a codebase that routinely calls function pointers with the wrong number of arguments. It compiles as C, but not as C++. Is there some legitimate reason for this to compile? As others have said, this is how old school C rocked I think the closest equivalent of int foo() in C++ would be int foo(...). It's not standards compliant like, at all, but in this particular case I think it's acceptable. Make sure to test it with all possible combinations of argument types, especially pointers, but in this one case where you have one compiler, one platform, one codebase, it's OK. Well, it will work for native code, I'm not sure how managed code will like it... OK, I tried. It works, both in managed and native mode. This code gives the same output when compiled with or without /clr: C++ code:
|
# ? Nov 9, 2014 14:21 |
|
rjmccall posted:Never do this. A full rewrite is off the table for a bunch of reasons. And "just make it use the right prototypes" is going to be annoyingly difficult, because they weren't just being fast-and-loose with types. It looks like they were actually using these like dynamic typing, but for function pointers. The same variable will be called different ways in different parts of the code depending on what happened to be previously stored in it, so just changing a type somewhere won't be sufficient. As I posted in the coding horrors thread, I found this bad boy: C code:
At this point I'm probably going to just leave this in its own C DLL and dynamically linking it in. The only reason I wanted a mixed-mode assembly was to avoid having a jillion DLLs that the program needs to run.
|
# ? Nov 9, 2014 17:28 |
|
GrumpyDoctor posted:
C code:
I will not in any way pretend this isn't terrible, but in your specific combination of compiler and environment it will work
|
# ? Nov 10, 2014 00:12 |
sarehu posted:Point of order: You keep saying "vector" in places where you mean "vector field". (e: And I assume by "each R->R component" you mean "each R->R^3 component".) Yeah, I meant vector field. By each component I think I meant R^3->R (ie: Ax takes a point, outputs the x component of the vector that's at that point in the vector field)
|
|
# ? Nov 10, 2014 04:08 |
|
OK, I found the library you're using, and you don't need variadic templates, all the functions have between one and two arguments. Also the code is very polite and dereferences function pointers before calling them, so you don't even need operator(). Add this to otypes.h, before FUN: C++ code:
C++ code:
Have you tried compiling the library as a native static library, and then linking to it?
|
# ? Nov 10, 2014 12:28 |
|
hackbunny posted:Have you tried compiling the library as a native static library, and then linking to it? Actually, no, I haven't. I have no idea why I didn't think to do that.
|
# ? Nov 10, 2014 18:23 |
|
Another question: Why does thisC code:
|
# ? Nov 10, 2014 18:32 |
|
Zerilan posted:By each component I think I meant R^3->R Erm.. yeah.
|
# ? Nov 10, 2014 19:03 |
|
GrumpyDoctor posted:Another question: Why does this Can you post the exact error?
|
# ? Nov 10, 2014 19:19 |
|
I have a question, and it doesn't necessarily need to be good form C but just needs to run. I have two files, a .c with a main and a .h that I need to add mutex/cv logic to in different ways for parallelization (using pthreads but I don't think that matters for what I need to know). The .h has one function that the thread uses with the parallelization stuff missing. The .c has everything else to make it work, and I shouldn't edit it at all. How do I initialize the mutex and CV so it'll be global, or at least shared by all the threads using the function in the header? I know for the ints I'm using as counters it's possible to declare and define them globally in the header since I'm only going to have one .c, avoiding collision, but the the mutex and CV I need to call the initialization, obviously not in the function for the threads, but not in the .c's main either.
|
# ? Nov 11, 2014 04:39 |
|
Thread libraries usually give you macros that can be used to constant-initialize mutexes and so on. For pthreads, these are PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER.
|
# ? Nov 11, 2014 18:28 |
|
Which are normally used at global or static scope in source files, not headers, but will probably work fine in this homework instance.
|
# ? Nov 11, 2014 23:12 |
|
GrumpyDoctor posted:Another question: Why does this Are you getting this warning when you compile the library, or when you compile your C++/CLI application? because if it's the latter, you probably do need to wrap the library's headers with extern "C" {} But yes, post the exact error
|
# ? Nov 11, 2014 23:45 |
|
pseudorandom name posted:Which are normally used at global or static scope in source files, not headers, but will probably work fine in this homework instance. Right. Understand that this assignment is not following the accepted best practice for splitting a program up across multiple files. Understand it, hold your nose, and act like your "header" is just another ordinary source file.
|
# ? Nov 11, 2014 23:57 |
|
Does anybody have a favourite c++ logging package? I'm thinking of going with glog, just for ease of use in getting started, but I'd eventually like to be able to hook it into some kind of remote logging facility (we currently have flume for another project, and if we could optionally send log events over the network that would be perfect).
|
# ? Nov 13, 2014 03:22 |
|
|
# ? May 14, 2024 21:08 |
|
You can send google-logging over the network with sawbuck, of course there are no server implementations. I just lifted the code straight from the Chromium repo, the "glog" package doesn't look like it helps much.
|
# ? Nov 13, 2014 03:53 |