« first day (181 days earlier)      last day (2678 days later) » 

1:34 AM
a instance variable that I am trying to set in a lambda function is always null
[](SomeInstanceMember * ptr) { ptr = somefunc(); }
 
ptr is local to the lambda
 
do i need to capture to set my class ptr?
 
@chewbapoclypse this is a parameter
 
[&ptr]() { ptr = somefunc(); }
 
probably, depending on what you intend to do
 
1:38 AM
i am just trying to set the pointer inside the lambda
but i have many pointers that I am tring to set so capture isn't a great solution
 
no, that's not what you intend to do
this is a mean of what you're trying to accomplish a thing you intend to do
 
ok let me show the function
 
void f()
{
    int* ptr;
    [&ptr](){ ptr = someFunc(); }(); // lambda immediately called, the ptr inside f is set
}
 
the last thre lines are missing para
i guess i could just return the texture...
 
yes you could
 
1:45 AM
just makes the code look ugly imo
 
out parameters are retarded
 
yea thats why std::tie exist sorta
 
also there's so much to say about this code I don't even
 
please do
i would like to know
i am not shy about critism
 
a.) why is it std::function and not a regular function b.) why are you passing arguments which are overwritten by the function c.) do you even need the surface
 
1:49 AM
from what I know
no the surface isn't used beyond creating the texture
its a lambda because it occurs inside another function only if a flag is set
 
@chewbapoclypse ??
 
is there a performance issue with it being lambda?
 
@chewbapoclypse in that case you can free it immediately
 
also for readability purposes and centralizing the code to where it is called
so create it inside the function gotha
duh i am a little retarded
 
and now you can return the texture directly
 
1:54 AM
std::function<void(SDL_Texture*, SDL_Color, TTF_Font*, int)>
            createTexture = [](SDL_Texture* tex, SDL_Color col, TTF_Font* font, int num)
        {
           SDL_Surface* surf = TTF_RenderText_Blended(font, std::to_string(num).c_str(), col);
            tex = SDL_CreateTextureFromSurface(TheGame::Instance()->getRenderer(), surf);
        };
 
@chewbapoclypse no performance issues with the lambda, but you're using std::function to store it
which is a polymorphic container for any callable
 
how do i create it without it?
 
auto
 
ahhh
nice
makes sense
i know i am nooby but this is good stuff
 
also I'd like to encourage to use more std::unique_ptr
 
1:59 AM
ok i have to go pick my buddy up from work thanks be back in 30-45 mins
i would like to know more and why you suggest that
 
they compose nicely and are a decent solution to memory management
 
 
10 hours later…
11:36 AM
a small C question.. how can I disable output channel? (no printfs at all in unit tests)
 
AKA reopen stdout to /dev/null
 
12:31 PM
3 messages moved from Lounge<C++>
 
 
2 hours later…
2:27 PM
Can someone help me with Makefile? I'm getting undefined reference error, even though I checked more than twice all the dependencies with gcc -MM *.c
 
nwp
@Osh24 Don't use makefiles. They will waste your time and never track dependencies correctly.
 
 
2 hours later…
4:32 PM
@Osh24 Well.... I would suggest using Autotools but the other guys here would stone me to death, so instead, I suggest CMake.
@Osh24 Also, be aware that sometimes ordering of .o and -lfoo switched does matter.
 
hey I still have my SQL issue
SDL sorry
18 hours ago, by PearlSek
#include "stdafx.h"
#include <iostream>
#include <SDL2\SDL.h>
#include <stdio.h>
#include "profile.h"

int main(int argc, char *argv[])
{
	std::cout << PHI << std::endl;
    return 0;
}
this code doesn't compile (1 unresolved external)
 
5:18 PM
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
 
Have you linked in SDLmain
 
yes
I used wmain and it works apparently
instead of main
 
well that's because SDL doesn't define wmain to do whatever it wants
you might as well do #undef main before
 
So SDL wouldn't work with this code :
#include "stdafx.h"
#include <iostream>
#include <SDL2\SDL.h>
#include <stdio.h>
#include "profile.h"

std::string x;

int wmain(int argc, char *argv[])
{
	std::cout << PHI << std::endl;
    return 0;
}
 
apparently this is so you have the same code on Android, iOS, Linux, Windows
If you don't really care much about portability you can simply #undef main and then declare your regular main
 
5:30 PM
wait a second i'll try if SDL works
it doesn't
unresolved external symbol _SDL_Init referenced in function _wmain
 
yes that's because the libraries are not linked properly
 
uhh i'll check
 
I'm not in front of the computer right now, but I'm fairly sure you need to check the linker settings in your project
Apparently SDL distributes project files for Visual Studio. Have you tried them?
 
yes
I've put the lib files in a folder
put this folder in the "Additional Library Directories" option
put SDL2.lib and SDL2main.lib in Additional Dependencies
 
6:06 PM
yes that should be enough
if it still doesn't work then you need to check all the previous settings whether they're correct
 
6:24 PM
here's my settings
FINALLY
I reinstalled with the 32-bits libraries
and dlls
 
hey all, i need some help understanding some concepts. this dumb, unrealistic snippet of C is overflowable. when compiled as a 32 bit binary you can over flow it with 16 characters (15 for the buffer plus 1 more to overflow the auth variable), making the printf("\nAccess granted\n"); execute. when its a 64 bit binary you need 29 characters. to overflow it in the same way. why is this? is there something very different about the stack in 64 bit?

#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {
 
1 message moved from Lounge<C++>
4 messages moved from Lounge<C++>
@Aaron x64 requires 16 byte aligned stack
also the pointers are longer
also there's a scratch buffer allocated by the function
 
6:42 PM
8 bytes for pointers on x64 right?
 
what is the stack on x86?
i actually thought 16 byte alignment is only enforced on arm chips
i've seen code that uses a misaligned stack on x64 before
 
AFAIR the only requirement on x86 is 4 byte alignment
 
on arm you get a SIGBUS
 
@Aaron it's broken too
 
6:44 PM
ah
which scratch buffer are you talking about?
 
read up on x64 calling conventions
the caller reserves a 32 byte buffer which the callee can spill registers into
 
ohhh
 
tbh in that program auth could be stored inside a register depending on the optimization settings
 
makes more sense now
so my whole memory layout is completely different on x64 then
 
@Aaron sometimes it might seem to work, but it's still broken since the callee can assume the stack is aligned and do SSE operations on the memory, which will result in crash on misaligned buffers
in other words, alignment is a correctness issue on x86 platform too
 
6:51 PM
oh, yeah i think in the case i'm thinking of there may not have been SSE involved
 
if not SSE then atomic accesses will stop be atomic
 
actually, let me get you the example
that is a patch i'm working on getting submitted to apache mesos. currently they pass a misaligned stack to clone(), i don't believe we or anyone else that uses mesos has seen a crash due to that
but, it does crash hard with a sigbus on aarch64
so is it only when SSE instructions are used that it becomes a fatal error on x86?
does the 32 byte buffer only apply on windows? https://en.wikipedia.org/wiki/X86_calling_conventions#Microsoft_x64_calling_convention
i'm on osx and linux FYI
"In the Microsoft x64 calling convention, it's the caller's responsibility to allocate 32 bytes of "shadow space" on the stack right before calling the function (regardless of the actual number of parameters used), and to pop the stack after the call. The shadow space is used to spill RCX, RDX, R8, and R9,[14] but must be made available to all functions, even those with fewer than four parameters."
 
@Aaron oh right, that's how it's called
I forgot the name
 
np
 
haven't done much x64 programming on linux, but I'm fairly sure it also has shadow space
 
7:04 PM
thanks for your help!
although, if there's 32 bytes of shadow space then i'm not seeing how 29 characters are needed for the overflow
i need 14 more bytes on top of the 15 that are in buff to overflow that int
on x64 i mean
 
you said you needed 16 bytes on x86 and 29 on x64
 
yeah
 
29 - 16 = 13
13 = 1 + 12
I think 12 is due to 16 byte alignment requirement
but I'm not quite sure now
 
hmm, wouldn't that not be 16 byte aligned then?
 
try disassembling, maybe it will tell you more
 
7:10 PM
ok let me do that
	.cstring
LC0:
	.ascii "\12Enter password: \0"
LC1:
	.ascii "password\0"
LC2:
	.ascii "\12Access denied\0"
LC3:
	.ascii "\12Access granted\0"
	.text
	.globl _main
_main:
LFB1:
	pushl	%ebp
LCFI0:
	movl	%esp, %ebp
LCFI1:
	pushl	%ebx
	subl	$36, %esp
LCFI2:
	call	___x86.get_pc_thunk.bx
L1$pb:
	movl	$0, -12(%ebp)
	subl	$12, %esp
	leal	LC0-L1$pb(%ebx), %eax
	pushl	%eax
	call	_printf
	addl	$16, %esp
	subl	$12, %esp
	leal	-27(%ebp), %eax
	pushl	%eax
	call	_gets
	addl	$16, %esp
	subl	$8, %esp
	leal	LC1-L1$pb(%ebx), %eax
that's on x86
	.cstring
LC0:
	.ascii "\12Enter password: \0"
LC1:
	.ascii "password\0"
LC2:
	.ascii "\12Access denied\0"
LC3:
	.ascii "\12Access granted\0"
	.text
	.globl _main
_main:
LFB1:
	pushq	%rbp
LCFI0:
	movq	%rsp, %rbp
LCFI1:
	subq	$48, %rsp
	movl	%edi, -36(%rbp)
	movq	%rsi, -48(%rbp)
	movl	$0, -4(%rbp)
	leaq	LC0(%rip), %rdi
	movl	$0, %eax
	call	_printf
	leaq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	_gets
	leaq	-32(%rbp), %rax
	leaq	LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_strcmp
	testl	%eax, %eax
	je	L2
that is x64
i need some time to learn how to read some of this
 
the subl $32, %esp and subq $48, %rsp instructions reserve the stack space
we can see the x64 reserves 16 bytes more, but it's not yet clear how it uses them
 
interesting...
 
(side note: not a fan of AT&T notation)
 
:)
 

« first day (181 days earlier)      last day (2678 days later) »