plethora of questions

Pages: 12
closed account (Dy7SLyTq)
a) does anyone have a good comment stripper for c++? i tried google but none were what i was looking for (none handled comments within strings and the would that looked promising was in python and i want to be able to make an elf file for easy use.

b) does anyone have software that turns code i find like on the internet into a style that i choose? for example, i am looking at bjarne stroustrops calculator but it is in a style that makes it difficult for me to read.

c) what is loop unwinding and how does duffs device work?

d) i want to make a library full of functions and classes that i have made for ease of access, but i want to link to it at run time (ie $g++ foo.cpp -o bar -lmylibrary). i think i need to make a .a or .so file but idk how to do it (it will be for linux btw so no msvs tutorials on creating dlls please)

thanks all in advance!
For a), why do you need a comment stripper anyway? Comments are meant to be useful, to make it easier to read.

For b), look into AStyle (Artistic Style), that sounds like what you want.

For c), loop unwinding is basically a technique that splits up loops into their component iterations, so as to make a program run faster, at the expense of having larger file sizes. I think you normally have to do this by hand, but some compilers will optimize this for you. I haven't heard of "duffs device", but that might be what it does.

For d), google knows all. If you have time, you can probably find a better one, but this gives the basic idea:
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
closed account (S6k9GNh0)
a) A code beautifier might be able to do that.

b) A code beautifier (google it).

c) Loop unwinding is causing a loop that will always iterate x times to simply execute x times instead of looping. This is faster because you don't have to test, increment, and initialize a counter. However, it can cause larger binary size and isn't faster in *all* cases, although I'm not aware of the special circumstances.

I also don't know what Duff's Device is...

d) Linking and run-time don't really go together. Are you wanting to use a library after your program has started? Please explain better.
Last edited on
closed account (Dy7SLyTq)
as to a) they are meant to be helpful but they arent always. and comments actually dont help me read source :p. i dont trust them

as to b) thanks ill check it out.

as to c) so its like making a list at what happens at each iteration? and yeah thats what duffs device does

as to d) thanks ill check that out

edit @computer:
http://en.wikipedia.org/wiki/Duff's_device

as to d) sorry i didnt mean to say at compile time. i want to link it at compile time
Last edited on
a) they are meant to be helpful but they arent always. and comments actually dont help me read source :p. i dont trust them


What if you don't want to read through tons of code to figure out what a function does? >_>
closed account (Dy7SLyTq)
i always do. i dont like to trust comments because they arent guaranteed what they do. and anything ill be reading right now wont be too bug. 200 lines or so. and at that size i just sit down and step through it with a piece of graph paper and kind of simulate executing it in my mind
closed account (S6k9GNh0)
I wish Linux input subsystem had more comments right about now. :/
closed account (Dy7SLyTq)
? what do you mean?
> sorry i didnt mean to say at compile time. i want to link it at compile time
me don't understand
you can't link at compile time
closed account (Dy7SLyTq)
yes you can.
$g++ foo.cpp -o bar -lmylibary
im compiling (ie compile time) and im linking to the mylibrary file
You are building. That invokes the process of compiling and linking.
The linking stage starts after the compilation is done, so it's outside compile time.
closed account (S6k9GNh0)
There are three stages we can visibly see. Compile time wich compiles code into objects. Link time which links objects into a blob, figures out what symbols goes where, etc. Then run time which is what happens whenever your applications entry point is called.
closed account (Dy7SLyTq)
sorry my mistake then. you guys understand what i mean though right?
closed account (S6k9GNh0)
There are two ways to link to a library at link-time.

One method is linking against a static library. This method makes a copy-similar of itself in your binary and code calls that section of your binary. This is advantageous for a few reasons. You don't have to worry about library versioning (well... you do each time you link against the library actually). You also don't have to worry about library location as its always in the binary.

The second method (and primary) is to link against a "stub" sort of library and have the linker figure it out on application start (pre-runtime). On the Linux platform, the "stub" is included inside of the shared library. and the linker figures everything out for you. On Windows, the stub and DLL are two seperate entities. It depends on platform and executable format but this method is preferred as you can update a library without the need to link stuff together again. It also allows for much smaller binaries and extreme reuse, especially whenever each program uses the same library over and over again.

Anyways, linking is easy enough. You can even link static and dynamic libraries into the same binary at the same time (depending on platform and executable format).

EDIT: Explain which one you might want, why you would want that method, and then I'll discuss how to go about it. :D
Last edited on
closed account (Dy7SLyTq)
thanks. i figured out how to write .a files, so thats fine and it actually solved my question above, but when i finish my compiler i want to modulize it into .so files so that i can update different sections (ie patches) without having to have the user download the whole ELF file again

edit: so i want to learn how to make .so files
Last edited on
closed account (S6k9GNh0)
If you're using GCC/Clang/Intel C++, just compile with the "-shared" flag.
closed account (Dy7SLyTq)
so if i want a library like libdts.so i would just compile with
$g++ -std=c++11 -c dts.cpp -o libdts.o -shared?
Why do you need a comment stripper? Just go through and delete all the comments.
closed account (Dy7SLyTq)
that can take a while to do. and im on a laptop with no mouse. its very inconvienent
closed account (S6k9GNh0)
Use Regex.
Pages: 12