Anonymous
Actually... probably it's me being an idiot I put my try/catch outside the WndProc, and the runtime exception is being risen in the WndProc could that be the problem?
I just read WndProc's documentation and was just going to suggest that if the send message is from a different thread then it will be a problem. This turns out to be the case if you send a message from a thread that did not create the window. But I wasn't sure if that was the problem in your case. Not a Windows developer.
Anonymous
Glad that you figured it out on your own.
Nomid Íkorni-Sciurus
yays
Nomid Íkorni-Sciurus
thank you for your help anyway
Felix
Excuse me, is there any book recommendations for introduction to data structures?
Anonymous
Can RAII be complex?
olli
Can RAII be complex?
Once understood, the principle behind RAII is pretty straightforward. You basically tie the life cycle of an acquisition to the lifetime of an object.
Anonymous
Once understood, the principle behind RAII is pretty straightforward. You basically tie the life cycle of an acquisition to the lifetime of an object.
yea, but can the complexity of lifetime management lead to complex RAII ? for example: an object manager can take ownership of other objects objects may also be transfered between object managers an object can be owned by another object an object could be shared between multiple objects and/or multiple object managers an object could become orphaned (not owned by anything)
Anonymous
yea, but can the complexity of lifetime management lead to complex RAII ? for example: an object manager can take ownership of other objects objects may also be transfered between object managers an object can be owned by another object an object could be shared between multiple objects and/or multiple object managers an object could become orphaned (not owned by anything)
You decide how a class is going to be used when you write the class. The way you implement RAII is decided by how your copy constructor, copy assignment, move constructor, move assignment and destructor behave. That alone decides what your RAII implementation looks like
olli
so RAII is seperate from that?
Yes, e.g. this codes does not use RAII to synchronize std::mutex m; void bad() { m.lock(); // do something if(!everything_ok()) return; m.unlock() } this one however does std::mutex m; void good() { // RAII class: mutex acquisition // is initialization std::lock_guard<std::mutex> lk(m); // do something if(!everything_ok()) return; } In the first example the acquisition of the mutex is not bound to any object and its lifetime so RAII does not apply, in the second example the lock ownership is tied to the lifetime of the lock_guard and hence RAII applies. The same goes for a shared_ptr, using it is RAII however its implementation cannot fully rely on RAII as the data might outlive the object.
Anonymous
alright 🙂
Dattu
Hello
Anonymous
how would i go about lifetime management for a Program class and a Shader class, in the case of this? "It is permissible to attach multiple shader objects of the same type because each may contain a portion of the complete shader. It is also permissible to attach a shader object to more than one program object. If a shader object is deleted while it is attached to a program object, it will be flagged for deletion, and deletion will not occur until glDetachShader is called to detach it from all program objects to which it is attached.”
Anonymous
this is my current program functions relating to Shader class void attachShader(const Shader & shader) { GL_CHECK_ERROR(glAttachShader(resource, shader.resource)); } void detachShader(const Shader & shader) { GL_CHECK_ERROR(glDetachShader(resource, shader.resource)); } and this is how i create a program static Program createProgram(const GLchar *vertexSource, const GLchar *fragmentSource) { Program p; p.attachToCurrentContext(); // register callbacks including rebinding and deletion callbacks Shader v(GL_VERTEX_SHADER, vertexSource); v.attachToCurrentContext(); // register callbacks including rebinding and deletion callbacks Shader f(GL_FRAGMENT_SHADER, fragmentSource); f.attachToCurrentContext(); // register callbacks including rebinding and deletion callbacks p.create(); p.attachShader(v); p.attachShader(f); p.link(); p.checkLinkStatus(); return p; }
Anonymous
attaches and detaches a shader to/from a program
Anonymous
attaches and detaches a shader to/from a program
I mean how does it attach? How do you maintain the relationship between Program and Shader? What datastructures are you using?
Anonymous
glAttachShader and glDetachShader are part of the OpenGL api
Anonymous
and currently i have no relationship between Program and Shader
Anonymous
glAttachShader and glDetachShader are part of the OpenGL api
Ok so in that case you don't control their implementation. But do you know if OpenGL actually takes ownership of shader.resource or does it expect you to maintain its lifetime as a caller?
Anonymous
a bit
Anonymous
how would i go about lifetime management for a Program class and a Shader class, in the case of this? "It is permissible to attach multiple shader objects of the same type because each may contain a portion of the complete shader. It is also permissible to attach a shader object to more than one program object. If a shader object is deleted while it is attached to a program object, it will be flagged for deletion, and deletion will not occur until glDetachShader is called to detach it from all program objects to which it is attached.”
Is this from OpenGL documentation then? The question is does OpenGL require you as a caller to maintain the lifetimes of the resources that are attached or does OpenGL take ownership of those resources. If it is the former then you will have to use the shared_ptr and weak_ptr concepts that I suggested in my first reply. If it is the latter, then you just pass on the resources to OpenGL and not worry about it. In this case, I am assuming that glDetachShader implementation will free the shader.resource when it is not tied to any program.resource
Anonymous
it is from https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glAttachShader.xhtml
Anonymous
Anyway it is pretty late for me. I will let someone else reply.
Anonymous
that’s ok
Anonymous
it appears that it is semi-controlled
Anonymous
https://gist.github.com/mgood7123/128ecf7de9614c63c404d979675f67d3
Jagadeesh
guys which youtube channel is good for c++
MRT
guys which youtube channel is good for c++
read book i think better than watch video for learning
Junaid
read book i think better than watch video for learning
Then recommend some books for Data structures and Algorithm
MRT
Then recommend some books for Data structures and Algorithm
Group professors have to answer the body, I do not have much experience :D
the Anupam
So tell me which programmes I should make first because I just j Learned c
the Anupam
If I get stuck in programming problem you guys will me in c, and c++
Anonymous
So tell me which programmes I should make first because I just j Learned c
https://github.com/rby90/Project-Based-Tutorials-in-C
Anonymous
These are good ideas^
Anonymous
Then recommend some books for Data structures and Algorithm
Algorithms 4th Edition by Robert Sedgewick ... Introduction to Algorithms by CLRS
Anonymous
Are they bigginer friendly
Oh. Emm maybe some.
the Anupam
Oh. Emm maybe some.
Ok I'll try
~Sennaire
Thank you
Anonymous
Has anyone here read the book "Effective C: An Introduction to Professional Programming"? Was it good? Would you suggest it to an intermediate C programmer? I was previously reading "The C Programming Language: A Modern Approach" but found that it wasn't suited for me.
Hsn
Oop and some of design patterns?
Anton
Hi guys! I have the following code in C. m = n; format++; n += parse_subsequence(&format, args); if (n < m) return (-1); How can I pass the address of format and simultaneously increment it? Pseudo code: m = n; n += parse_subsequence(&++format, args); if (n < m) return (-1);
Phoenix
#include<iostream> using namespace std; void update(int *a,int *b) { *a=(*a)+(*b); cout<<*a<<endl; if(*a>*b) { *b=(*a)-(*b); cout<<*b<<endl; } else {*b=(*b)-(*a); cout<<*b<<endl; } } int main() { int a,b; cin>>a>>b; cout<<update(&a,&b); return 0; }
Phoenix
This code is giving error : no match for 'operator<<'
Anonymous
&format++ maybe ? Eh, just put format++; in following line .. more readable anyway.
No. This is UB. post increment operator on ints returns a temp and you are passing the address of this temp variable (which will be destroyed at the end of the expression) to a function.
Anonymous
UB?
Undefined Behavior
Hsn
I see, its an (output variable) .. so function might change it
Anonymous
I see, its an (output variable) .. so function might change it
Irrespective of whether you change it or not, it is still Undefined Behavior. Even if you just read the value it is UB.
Anton
Did you try your pseudocode? It would work.
I tried it and it gives me an error: P.S. Sorry, I should have mentioned it earlier, parse_subsequence is prototyped like this: int parse_subsequence(const char **format, va_list args) Error: ft_printf.c:91:27: error: cannot take the address of an rvalue of type 'const char *' n += parse_subsequence(&++format, args);
Anonymous
Ah because its not used after?
It is because the pointer is an invalid pointer
Hsn
It is because the pointer is an invalid pointer
Ohh .. i though its &(format++)
Hsn
There is no point of incrementing the address anyway unless its stored in ptr
Anton
What is format?
const char *format
Hsn
Why u dont write this: format++; Subsequent (&format,...);
Anton
Why u dont write this: format++; Subsequent (&format,...);
This might sound stupid, but online judge will not accept the function with 25+ lines in it. And I'm currently having 26.
Hsn
Does &(++format) work?
Anton
Does &(++format) work?
No, gives me the same error
stear
Hi,Can we make a gui in C ++ without any framework like gtk or qt? If so, how should we do this? Do you have a source? I searched a lot, I did not get anywhere, I do not know, maybe I do not know how to search
Nameful
You can, but it's hard
Nameful
Why do you want to do that?
stear
You can, but it's hard
Please explain how
stear
stear
Qt framework has the ability to add style css How to do this in c ++ without the help of qt Please, if anyone knows, help me
Nomid Íkorni-Sciurus
Qt parses and compiles CSS and draws to GDI/GLUT contexts based on OS, frame type (window) and shape (and other variables. I don't know if Qt draws directly on framebuffer, but I know it will use OpenGL whenever possibile)