Dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

en.wikipedia.org/wiki/Nm_(Unix)
graphics.stanford.edu/~seander/bithacks.html
twitter.com/SFWRedditVideos

Exactly, there's only one function in there, a function with C linkage. There is no wrapper, and there is no mangled function name.
>Check the ELF symbols. You will doubtless find the two functions you declared: one fucked mess of a name that points to the C++ function, and the clean C function name that was actually exported as the program's ABI.
You are incorrect, I showed that.

What is the best lambda calculus and why is it the CoC?

Have you ever thought of programming an AI just to have a friend?

>Can you just write everything in a low level language like C, C++, or Rust?

Yes.

>Should you?

I dunno. It's your call. Weigh the cost-benefits.

>Is there even any point to Java, C#, and all that other crap that needs you to install various runtimes and such?

Yes. They are high performance virtual machines that programs run on top. It's easier to target the JVM by emitting Java byte code than to target x86 by emitting machine code.

So? It's well-known that C isn't a strict subset of C++.

>declares no C++ functions
>where are my C++ symbols in the ELF????

>Check the ELF symbols. You will doubtless find the two functions you declared: one fucked mess of a name that points to the C++ function, and the clean C function name that was actually exported as the program's ABI.
You're wrong.
>Because the function definition contains C++ code. The function declaration however is C.
Can Java function contain Haskell code in it? If not, how can C function contain C++ code in it?

Because CoC is all you need.

Meant to

even ai would hate me ;_;

>T my_atoi
>all those fuckhuge type information-prefixed C++ stdlib symbols
>"you're wrong"

Try exporting those traits lmao

foo is a C++ function, though.
$ echo 'extern "C" int foo() { class sepples{}; return 0; };' > main.cpp; g++ -c main.cpp
$ nm main.o
0000000000000000 T foo

That's not a C function, it's using C++ features. Still no wrapper.

>So?
so you can't

>moving the goalposts

These are imports, the only function being exported is my_atoi, and it contains C++ code directly, while you claimed
>You will doubtless find the two functions you declared: one fucked mess of a name that points to the C++ function, and the clean C function name that was actually exported as the program's ABI.

>I got told HARD

2D radiosity-based lighting.

>AT&T syntax
tl;dr

did you expect JS syntax?

I expect Intel syntax
AT&T is far beneath me

Trying to reverse engineer the steam API in order to automatically farm cards and sell them.
I got the farming part but I still have to figure how to interact with the market API. Reverse engineering really isn't as fun as I thought it was.

It's not about the assembly, it's about the fact that my_itoa contains code compiled from C++ and even calls to functions from C++ standard library.

>I scoped the class to the function

I don't even remember if that's possible. Do you even know what you're doing

I've been saying the exact same thing over and over. You simply don't understand what I'm talking about.

Try referring to _ZNSt7__cxx1119basic_istringstreamIcSt11char_traitsIcESaIcEEC1ERKNS_12basic_stringIcS2_S3_EESt13_Ios_Openmode through the ABI in a portable manner.

That's exactly what I said.

I told you that you'd find the C++ stuff, and the actual exported C symbol that calls your C++ stuff.

That's exactly what you found.

It implies C++ isn't even trying to have an ABI.

>Try referring to...through the ABI in a portable manner.
You made a general statement about C++ functions, not specifically C++ template functions. An extern "C" function is still a C++ function, it just has a constrained signature.

>arguing with sepples fags
When will you learn?

I'm proving you wrong. The body of the function compiles as C++, but does not compile as C. It use C++-specific features. Therefore it is a C++ function and not a C function. There is only one symbol in the object file. That is the C++ function I have written. There is no wrapper, and there is no name-mangled function.
You are provably incorrect and all you have left is to try to change the subject by being astonished at basic C++ features.

>create jar
>10kB
>n-nani?!
>oh wait, it lacks all libraries
>create fat jar
>20MB
>that's the power of java

DELET!

Fucking sepplesfags ruining yet another thread with their incoherent sperging.

Yeah but with jvm you can use any language that just compiles to java bytecode. It's also decently fast. You can just deploy the compiled bytecode and tell people to install java, they likely have it already installed. No need to bother with low level linking, distributing platform/compiler specific shared libraries and such.

You're a dense one, aren't you? You said
> Check the ELF symbols. You will doubtless find the two functions you declared: one fucked mess of a name that points to the C++ function, and the clean C function name that was actually exported as the program's ABI.
I've shown, that there's only one function being exported, without mangling, containing C++ code directly in it. Mangled names are imports, not exports. The function doesn't call "C++ stuff", it contains its code directly.
>It implies C++ isn't even trying to have an ABI.
Is this supposed to be some kind of revelation? C++ never had standardized ABI, by design.

>>n-nani
kys

>create app.min.js
>10k
>oh wait, it lacks a browser
>100MB
>the power of webshit

>You said
wasn't me tho

>kys

ky's you're a self

>Yeah but with jvm you can use any language that just compiles to java bytecode. It's also decently fast. You can just deploy the compiled bytecode and tell people to install java, they likely have it already installed. No need to bother with low level linking, distributing platform/compiler specific shared libraries and such.
JARs are comfy indeed. They just work.

Just statically link your programs if you don't want to bother with distributing shared libraries. That's what Rust and Go do by default.

Are shared libraries really a good idea any more?

I think they should just go but I'm sure you'll find autists here and elsewhere ready to defend the benefits of shared libraries.

OS/driver libraries should be shared. Everything else should be static (and dynamically link to the aforementioned libraries).

I'm an optimist.

>You made a general statement about C++ functions, not specifically C++ template functions

Who even said anything about templates? Let's not open that can of worms. Try referring to a simple non extern "C" function through the ABI.

>An extern "C" function is still a C++ function, it just has a constrained signature.

Yeah, you constrained your C++ function's signature to the point where it's literally a C function. You can't even do the thing name mangling was created for in the first place: function overloading.

It's totally a C++ function though! It totally has C++ ABI despite the "C linkage"! I mean, really...

Why don't we stop talking about functions then? Try calling an method (= member function) on a C++ object through Python. And don't make me a silly wrapper function to do it for you.

>scopes declarations to the function
>makes zero references to symbol
>calls zero (0) functions
>lol why aren't them in the object file?
>your wrong

>containing C++ code directly in it
>The function doesn't call "C++ stuff"
>it contains its code directly.

>return 0;

Yeah, nice code you got there.

I see you're one of those guys who can't even begin to imagine the assembly the compiler will generate. C++ tends to do that to people.

>C++ never had standardized ABI, by design.

Neither did C.

>Try referring to a simple non extern "C" function through the ABI.
>moving the goalposts yet again

>I said "try calling a C++ function".
I did. That's over.
Your condition was never that all C++ functions could be called outside of C++. Nobody ever said that was possible. But some C++ functions can be called outside of C++, that is proven.
What you're doing now is called backpedaling.

I'm just giving you different examples so that you can understand.

Why? Because I asked you to interface with a C++ function, and you interfaced with a C function.

In other words: I asked you to link against a C++ symbol. You linked against a C symbol.

How hard can this be?

Symbol =/= function

>all C++ functions could be called outside of C++
>Nobody ever said that was possible

Welp.

>extern "C"
>C++ function

Just because it contains C++ code doesn't mean it's a C++ function.

You have a strange idea of what constitutes a C++ function.

>What you're doing now is called backpedaling.
His original point was that the C++ ABI is a joke (which it is). Nowhere have you proven him wrong.

>Just because it contains C++ code doesn't mean it's a C++ function.

I've never argued against that, the C++ ABI is a joke. But that was never the real point.
>Try calling a C++ function from Python.
There's a C++ function which can be called from Python! But it's not a C++ function despite being written in C++, because reasons.

When you do extern "C", you're telling the compiler not to name the function name. This naturally rules out functions that require name-mangling. The content of the function is irrelevant. As far as the function signature is concerned, it might as well be a C one.

>As far as the function signature is concerned, it might as well be a C one.
It's still a C++ function. How hard is this to understand?

not to name-mangle*

C FUNCTIONS ARE JUST ASSEMBLY SUBROUTINES BECAUSE THEY'RE COMPILED DURR HURR

No I have an extremely clear idea of what a C++ function is. You're the one who's confused.

Even wikipedia knows the difference:

en.wikipedia.org/wiki/Nm_(Unix)

# nm test.o
# C
0000000a T global_function
00000025 T global_function2
00000004 C global_var
00000000 D global_var_init
00000004 b local_static_var.1255
00000008 d local_static_var_init.1256
0000003b T main
00000036 T non_mangled_function
00000000 t static_function
00000000 b static_var
00000004 d static_var_init

# nm test.o
# C++
0000000a T _Z15global_functioni
00000025 T _Z16global_function2v
00000004 b _ZL10static_var
00000000 t _ZL15static_functionv
00000004 d _ZL15static_var_init
00000008 b _ZZ15global_functioniE16local_static_var
00000008 d _ZZ15global_functioniE21local_static_var_init
U __gxx_personality_v0
00000000 B global_var
00000000 D global_var_init
0000003b T main
00000036 T non_mangled_function

>hey! mr. compiler! mr. C++ compiler!
>please come over here.
>I must speak with you for a sec
>you see, I wanna declare this here function
>but look now. I need you to pay attention
>even though I will be writing C++ code in it
>I need you to export it as if it was a C function
>that is why I'm writing this bit here extern "C"
>understand now mr. compiler?
>good!
>i will let you do your thing now!

>It's still a C++ function.
Not in any sense that's relevant to the ABI discussion. When you say extern "C", you're effectively saying "use the C ABI for this".

>What are you working on, Sup Forums?
Have you guys ever wondered why dpt is so inquisitive? Why does it ask all these questions, thread after thread, day after day? What is dpt:s endgame?

>as if
Key phrase here. It remains a C++ function, only difference is that it has a C-friendly name.
You can call C++ functions from Python, user. That's how you do it. It does not transform into a different language by adopting that language's linkage conventions.

It gets boring at some point.

>What is dpt:s endgame?
RMS for president.

If I need to create a string of characters that takes less no more than 25 characters with what subscript value would I declare the string?

>a string of characters that takes less no more than 25 characters
????

not possible

Depends on whether the null terminator is one of those 25 characters.

Please refrain from shitposting, okay? Thanks.

It's named like a C function, passes parameters like a C function, saves registers like a C function, gets exported as a symbol like a C function...

Are you really telling me it's a C++ function?

Writing C++ for a point of sale business. Most of the code started in the 90s but since its C++ its pretty much still working fine. In house data solution is based on btrieve, fast as fuck but you have to be an autist to learn to use it.

Yeah it's a C++ function, because everything inside it was written in C++.
Being able to use the calling conventions of a different language does not change the language it was written in. You said you can't write a C++ function which can be called from Python, but you can by using a common convention.

>It remains a C++ function
Calling something a "C++ function" after it's been compiled down to assembly and uses the standard C naming scheme and calling convention is meaningless.

Now you're getting it. Just because it's meaningless doesn't mean you can say it's not true.

>Just because it's meaningless doesn't mean you can say it's not true.
But that's obviously not what that other sepples fag meant. You've turned it into a retarded argument about semantics, probably because you realized you're wrong.

Calling it a C function is meaningless too. It's a subroutine with the C calling convention. But if it came from C++ code, it's a C++ function.

Yeah so you used some language feature to make a C function from within C++. You can totally export C++ functions!

Call me when Python supports things such as the thiscall ABIs (note the s, for there are many). Actually don't call me. I seriously doubt they will ever be able to resolve the fucked names. Nobody is man enough to even try.

My point is that's what's necessary in order for C++ to actually play nice with anything but other C++ programs. Sure, you can restrict yourself to a C interface... And kiss C++ goodbye. Hope you didn't like object orientation or templates.

No you're wrong, a Java method with JNI bindings is actually a C function.

>Calling it a C function is meaningless too. It's a subroutine with the C calling convention.
Calling it a C function is meaningful, because if I tell you it's a C function, you know how to call it properly. If I tell you it's a C++ function, it tells you nothing.

It's a C function in its interface, but it remains a C++ function in its implementation. Your problem was that you could not implement a function in C++ and then call it from Python.

>premature optimization
Why did Knut get quoted on that and not his much more accurate and convincing quote just a paragraph earlier?
People tend to call things premature optimization when they're actually too stupid to try.
I'm not for reading and memorizing graphics.stanford.edu/~seander/bithacks.html and using it as soon as you get a chance of course. Those don't require anything of you to do. And where they can be done productively the compiler does it. But people yell at me about premature optimization when I'm packing my structs that will be allocated in 4mb chunks with a modicum of intellect.
I'm really sick of it. I believe this is why software sucks today.

>it remains a C++ function in its implementation
Sorry to jump in but I'd contact the standard if you've written a compiler that can do this effectively. Lots of people who use the C ABI don't do it extensively enough to realize the issues (in making C++ code work with it) but if you have people would be VERY appreciative.

>It's a C function in its interface,
Correct.

>but it remains a C++ function in its implementation
Incorrect. It gets compiled and ceases to be a "C++ function in its implementation". If you can identify it with any language at that point, it's C.

>Your problem was
Different poster. I think the other user got tired of arguing with someone as dense as you appear to be.

Not him. I'd just like to note that virtual machines are different. One can never interface with the virtualized code directly, only with the virtual machine.

In other words, from C one doesn't talk to Java but to the JVM. You ask it to call methods for you, using a notation that is eerily similar to fucked C++ symbols:

helloWorldClass = (*env)->FindClass(env, "example/jni/InvocationHelloWorld");
mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V");
applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL);
applicationArg0 = (*env)->NewStringUTF(env, "From-C-program");
(*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);

Unlike C++ though, this format is de-facto standardized.

>it remains a C++ function in its implementation

We're talking about interfaces. It's astounding that you think the implementation matters.

The implementation matters because that's what you said was not possible in . I read this as an assertion that you cannot write a function in C++ which can be called in Python.
If you meant something else then I don't think we have a problem.

Cargo cult. Same reason people quote Dijkstra despite never having read or even understood the original paper.

Well obviously! You can call a C++ implementation from any language -- if you wrap it in a C package first!

Try doing this from Python (or any language):

cpp_object->member_function(arg1, arg2);

And don't make me a wrapper function to do it for you.

Daily reminder.

>might throw exception
>might do anything what the fuck sepples implementations do now days, crash for no reason?

How do emulators stay true to the speed of the original hardware?

For example, every little instruction on a Z80 takes so little time it would be unrealistic to "sleep" to fill out the remaining nanoseconds. At what point then do you slow down?

Do I learn Python 2 or 3?

3

I'm not gonna try to prove something that can't be proven. You can't take any C++ function and make it as visible as a C function, and nobody ever said that.
In the end, the only solution is to drop to the lowest common denominator. It sucks, but it is a solution.

Are extern "C" functions not implicitly noexcept? If not then that's a serious oversight.

>every little instruction on a Z80 takes so little time it would be unrealistic to "sleep" to fill out the remaining nanoseconds
You just count cycles for every instruction and only perform X cycles per timeslice.

How long should it take someone very familiar with C and OOP principles to pick up C++?

I want to write a short project in C++ to put on my portfolio but I don't have a lot of time before I have to submit my resume. I would write the project in C otherwise but I'd like some solid C++ experience

Why are the values of i and sum respectively 100 and 45 at the end of the program? I understand there's some assignment/initialization fuckery going on but I can't determine where it is
#include

int main()
{
int i = 100, sum = 0;
for (int i = 0; i != 10; ++i)
sum += i;
std::cout

Depends how in depth you go. C++ is a very big, very complicated language. Everyone writes it differently too.

You don't need to sleep for every instruction, only for input and drawing.
Also why would it be unrealistic to "sleep" it out? If you can't just sleep you can inline assembly do nop commands until it's long enough. Though with modern operating systems I think it's hard to synchronize because you can't know how much processing time is allocated to your program even if you knew how many commands your program uses.

The i used inside the for loop is a different i. The original is left untouched. Sum is just 0+1+2+3+4+5+6+7+8+9=45

You declared two i variables.

>You don't need to sleep for every instruction, only for input and drawing.
You do have to cap the number of instructions per frame somehow.

>Also why would it be unrealistic to "sleep" it out?
Not enough resolution.

>If you can't just sleep you can inline assembly do nop commands until it's long enough
And what, tune it to the precise speed of your machine? That's retarded.

Anyone know why this is raising an error on "ambiguous types?"

I tried implementing the top part of the code with the bottom function, but for some reason the pattern guards aren't working as I'm intending it to work:

--works fine
testZip :: [a] -> [b] -> [(a, b)]
testZip [] _ = []
testZip _ [] = []
testZip (l1_head : l1_tail) (l2_head : l2_tail) =

--raises error in picture attached
testZip2 :: [a] -> [b] -> [(a, b)]
testZip2 l1 l2
| [] _ = []
| _ [] = []
| otherwise = (head1, head2) : testZip2 tail1 tail2
where (head1 : tail1) = l1
(head2 : tail2) = l2

So the for's i is local to for and to call the main's i I would have to use ::i?

for (int i = 0; i != 10; ++i)

this block of code can be read as

int i=0;
while (i != 10){
// do stuff in the loop
++i
}

>I would have to use ::i?
No, that would refer to some global namespace i (which doesn't exist). You can't refer to the original 'i' inside the for loop because the other 'i' shadows it.

>>If you can't just sleep you can inline assembly do nop commands until it's long enough
>And what, tune it to the precise speed of your machine? That's retarded.
That's what we have done with microcontrollers but there it's easier. Having operating system and multiple threads kind of fucks that one up.

Yes. It's said that the for's i shadows the main's i. Always use braces so that the new scope is clear:

#include

int main()
{
int i = 100, sum = 0;
// main's i is visible here

for (int i = 0; i != 10; ++i) {
// for's i is visible here, shadowed main's i
sum += i;
}

// main's i is visible again
std::cout

What's the difference?