r/cpp • u/PancakeMSTR • Apr 09 '16
Reading C++ code way over my head, could use ANY guidance.
[deleted]
2
u/PC__LOAD__LETTER Apr 09 '16
I assume you have access to the source code and you're not trying to reverse engineer this thing? Are you using an IDE? If working in Linux, are you comfortable with grep?
If it were me I'd just start by looking at function names. First for anything that contains both "get" and "gps" (or "position", "pos", "location", "loc", "coordinates", "latitude", "longitude", etc..), and then just any one of those by themselves.
What libraries are being used? What header files are included?
Edit: Completely missed the fact that you're looking for time and not location, oops. Try just searching for "time" or "clock" instead of the other stuff.
1
u/PancakeMSTR Apr 09 '16
I'm comfortable with linux, but not so much with grep? This is something that will locate strings, right?
1
u/PC__LOAD__LETTER Apr 09 '16
Yeah, it just searches for strings. For example, try:
grep -nr "time" /path/to/top_level_directory-n means that it will print the line number before printing the file and line of each match
-r means recursive (it will search all of the files in the target directory and subdirectories)
And don't forget to replace "/path/to/top_level_directory" with the real path ;)
1
u/PancakeMSTR Apr 09 '16
I'll look into that, thanks.
1
u/PC__LOAD__LETTER Apr 09 '16
Sure. I'm betting this is probably sensitive company material, but on the off chance that it's not you could throw it up into Github and I'd be happy to take a peek.
1
u/PancakeMSTR Apr 09 '16
Yeah half of it is open-source and half of it is proprietary, so I can't really be sharing it. Thanks though.
1
u/devel_watcher Apr 09 '16 edited Apr 09 '16
I've got 'grep -rIn' in my muscle memory. The 'I' excludes binary files. Some old codebases have binary garbage in them.
grep -rIn "time" /path/to/top_level_directory
Also, be sure to have everything in GIT. Then your changes are seen clearly with 'git diff' and you can save them on the temporary branches.
By the way, search by the file name for myfile.cpp is
find . -name myfile*orfind . -name \*file.cpp
1
u/liquidify Apr 09 '16
You should do some basic studying of embedded system programming and then attempt to do some hard research into the specific hardware you are dealing with. Most hardware systems with low level code have some pretty specific methods for input and output between the hardware and software... so, most likely whoever wrote the code was following some pretty defined standards created by whoever made the hardware.
This stuff isn't rocket science if you know how to read the technical data sheets, but if you don't, and if you don't have a good understanding of programming at a low level, you have a couple options....
Learn how, or hire someone who knows how. Typically people who do what you are talking about are computer engineers or computer scientists.
Of course, take my advice for what it is : the ideas of someone who was given very little information about your problem, and thus I may have bad answers for your specific situation.
1
u/PancakeMSTR Apr 09 '16
embedded system programming? I know I can look that up, but in your words, what does that mean?
1
u/liquidify Apr 09 '16
Basically they are pieces of code that are written to interface very deeply with hardware and directly control or read from the hardware. Often, you will find embedded systems inside of small computers that are built into devices. For example, in a typical remote control for your TV, there might a microcomputer that has incredibly small amounts of processing power and memory, but you can program it if you have the ability to access it and the right understanding of the "code" used to access its individual components.
Another example is that you might have a device that has a motion sensor and an LED. Perhaps you would like the LED to turn on if someone enters the room. Certainly, you could use a real computer for this, but that level of power is not necessary for such a task. So the hardware manufacturer will put a very cheap computer inside the device and then write specification sheets for how to write code that allows you to control the components. Sometimes if you are lucky, they will provide you will a header file for your code to get you started. As an engineer, it is your job to interact with the hardware and "embed" your code in it so that the device will behave how you want it. Of course this is a pretty loose way to talk about the field.
Computer engineering or computer science are deep and difficult degrees depending on what direction you want to go within the fields. But these degrees are typically where you would study such systems. This type of stuff isn't easy, and that is why computer engineers and computer scientists typically make a lot of money.
2
u/PancakeMSTR Apr 09 '16
Yeah I admit I'm just a lowly physicist trying to do software engineering here.
1
u/liquidify Apr 09 '16
lol, lowly.
1
u/PancakeMSTR Apr 09 '16
I may come off as pretentious saying that, but I'm not trying to be. This programming shit is way over my head most of the time.
1
u/XenonOfArcticus Apr 09 '16
I do this sort of stuff for a living and am doing something similar right now. Contact me privately if you want to.
1
u/PancakeMSTR Apr 09 '16
Maybe, my questions are really way too vague to direct to anyone in particular at this point. I edited my post to add some new information. Take a look at that, and thanks for offering to help.
1
u/XenonOfArcticus Apr 09 '16
I kinda think you're in over your head. How important is it to solve this?
1
u/PancakeMSTR Apr 09 '16
Kind of. Fairly. It's pretty important I at least make SOME progress.
1
Apr 09 '16
You are giving off the impression that you aren't a programmer, or at the very least, don't understand C/C++/Java like languages, which every programmer does.
-1
u/dodheim Apr 10 '16
don't understand C/C++/Java like languages, which every programmer does
You'll find lots of people in the ML/Haskell communities who develop software for a living who wouldn't know the difference between C, C++, and JavaScript if you gave them an hour. I love C++, but the world is a little bigger than this... ;-]
1
u/XenonOfArcticus Apr 09 '16
PM me. I can probably help you read the code. Otherwise you aren't going to make much progress.
1
u/PancakeMSTR Apr 11 '16
So the open source part of why I'm working on is this: SyntroCore
I'm not really sure what syntrocore does, could you help me understand it?
1
u/XenonOfArcticus Apr 12 '16
Well, as a basic bit, SyntroNet looks like a transport system for sending a variety of realtime data (audio, video, sensor data) around a network. SyntroCore is a library for sending and receiving data on SyntroNet. What are you trying to do, exactly?
1
u/PancakeMSTR Apr 12 '16
So this thing is a big fancy microphone. It records audio data and stores it. That audio data then goes into an even fancier algorithm for analysis, but I'm not part of that. I'm only working on the part where it records audio and, in particular, exactly at what times the device thinks its recording (i.e., how does it know what timestamp to write down very each recording?)
1
u/XenonOfArcticus Apr 12 '16
Ok. And is SyntroNet the code that runs the mic? Or is it custom code built on top of SyntroCore? Can you post a link to the code that talks to the mic and pipes the data into SyntroNet?
1
u/PancakeMSTR Apr 12 '16
Yeah that's about the point where I actually don't know what's going on. I'll check in with my superiors, and see what they say. After that I'll get back to you.
1
u/XenonOfArcticus Apr 12 '16
Ok. PM me and we can discuss it more by email. I can probably explain whatever you need to know.
2
u/dalailambda Apr 09 '16
C++ isn't the easiest language to just jump straight into if you have no experience with it, so if your problem is that the code itself is hard to understand, I'd recommend doing a tutorial just to get up to speed.
Since you're working with embedded systems I'd suggest this guide which is very digestible in my opinion.
Also I'd recommend using an IDE. Visual Studio, CLion, CodeBlocks, or Xcode are the big ones. It will help you a lot with trying to understand what the code is doing, allow you to easily move between functions, and most importantly for your case, it can show you the structure the classes form.
2
u/Rangsk Apr 09 '16
A few suggestions:
Run the code in a debugger. Find the entry point and start stepping through it line-by-line. Get an idea of how it flows and where it goes. I recommend doing breadth first, rather than depth first. That means use "step over" more often than "step into".
Log to file. Add lots of logs. Scatter them everywhere. Log at the start and end of every function, with the name of that function. Log inside functions when interesting things happen. Inspect your logs to get an idea of the program flow and what it does.
This really depends on what you're working with, but there is often documentation and samples which come with the device you're interfacing with that is provided by the manufacturer. Reading the docs and learning how the samples work can be very helpful for finding where the same things happen in the actual code.
1
u/cyanobyte Apr 11 '16
Welcome to the main job of programming, grocking a previous code base so that you can modify it without breaking it.
Use a good IDE with Refactoring (I use Visual Studio or CLion):
Right click on any definition and find references will show you any usages of a function.
Right click on a unknown function and click go to definition.
Walk the code for as long as it takes to map how it works.
After you form a hypothesis on how something works make a small experimental change to prove/disprove it.
Mix, Stir, Repeat.
Welcome to programming!
9
u/sumo952 Apr 09 '16
This doesn't sound like a well-written C++ codebase. It sounds like an awful, old, legacy, C-style "C++" codebase. Or one where OOP has been terribly overused and not well-structured. You're deep in the shit. Sounds definitely too much for a beginner.
Some people recommended grep - I would not recommend that to somebody like you from what I've read, except you're really a linux shell wizard already. But you didn't even know grep, so you definitely are not. So. Use an IDE. Use a good IDE. One you like. Try QtCreator first. It's one of the best on linux. CLion also, but I think it's not free (the EAP might be). An IDE will help you immensely navigating the code. (If you can run the software on Windows (it sounds like you cannot), use Visual Studio 2015. Period.)
Debugging. Debug the code. Don't try to understand the flow and everything from just reading the code. Run it. Live-debug it in a debugger. The IDE will help you massively with that. You can set breakpoints, step through the code, watch variables in each step.