Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

LockeNess Monster posted:

The only thing missing is good code formatter and not freezing.

So basically the things missing from it are 1) one of the main things you'd expect from any editor this side of Notepad, and 2) one of the main things you'd expect from any application this side of Windows 95.

Also it boggles my mind that anyone would have a hard time figuring out Visual Studio.

Avenging Dentist fucked around with this message at 02:40 on Mar 19, 2010

Adbot
ADBOT LOVES YOU

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
At least its not an overcomplicated confusing mess that is VS.

Seriously I worked on some small projects in Windows and DevC++ and other than occasional freezing it was relatively pain free.

Crazy RRRussian fucked around with this message at 02:42 on Mar 19, 2010

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

LockeNess Monster posted:

At least its not an overcomplicated confusing mess that is VS.

How is VS confusing? You basically install it and press a couple buttons and start typing. Once you learn the build/run/debug shortcuts you don't even need to look at the menus 99% of the time.

Of course, the real question then is why not pick something decent like Eclipse (ok, I'm being charitable here, but at least Eclipse doesn't usually crash), or emacs/vim? I mean seriously, a text editor that freezes is basically the worst possible editor to pick unless it just continually saves your work due to its own knowledge about how lovely it is.

Crazy RRRussian
Mar 5, 2010

by Fistgrrl

Avenging Dentist posted:

How is VS confusing? You basically install it and press a couple buttons and start typing. Once you learn the build/run/debug shortcuts you don't even need to look at the menus 99% of the time.

Of course, the real question then is why not pick something decent like Eclipse (ok, I'm being charitable here, but at least Eclipse doesn't usually crash), or emacs/vim?

If I need to develop in C++ i code in linux (using gedit or Eclipse, I know I should probably learn vim or emacs). If I need to port it to Windows I get it to point where I can compile it using cl.exe or in DevC++ and continue writing actual code in linux.

Crazy RRRussian fucked around with this message at 02:46 on Mar 19, 2010

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

LockeNess Monster posted:

If I need to develop in C++ i code in linux (using gedit or Eclipse, I know I should probably learn vim or emacs). If I need to port it to Windows I get it to point where I can compile it using cl.exe or in DevC++ and continue writing actual code in linux.

Then why do you even have an IDE? Why not just cross-compile?

Crazy RRRussian
Mar 5, 2010

by Fistgrrl

Avenging Dentist posted:

Then why do you even have an IDE? Why not just cross-compile?

For syntax highlighting, code folding and code formatting? Also I occasionally use refactoring tool in Eclipse.

Meh, I should probably pick up Visual Studio, but right now all of my C++ development needs are satisfied by using Eclipse in Ubuntu running in my VMWare.

OddObserver
Apr 3, 2009

LockeNess Monster posted:

For syntax highlighting, code folding and code formatting? Also I occasionally use refactoring tool in Eclipse.

Meh, I should probably pick up Visual Studio, but right now all of my C++ development needs are satisfied by using Eclipse in Ubuntu running in my VMWare.

You don't need an IDE for the first 2, and real men don't write code that needs reformatting ;-). But why not use Eclipse on Windows too, if you like it?

Crazy RRRussian
Mar 5, 2010

by Fistgrrl

OddObserver posted:

You don't need an IDE for the first 2, and real men don't write code that needs reformatting ;-). But why not use Eclipse on Windows too, if you like it?

Only use Eclipse for Java on Windows. Couldn't figure out how to use mingw with Eclipse on windows in 20 minute so gave up and stopped caring.

floWenoL
Oct 23, 2002

LockeNess Monster posted:

I don't really understand all the hate for DevC++. Sure it freezes occasionally, but it is a lot simpler and more straightforward to use and learn how to use than Visual Studio. It is pretty easy to set up C++ projects in it and have them compile and run fine. The only thing missing is good code formatter and not freezing.

If you can't figure out how to use Visual Studio, then you have no business programming C++.

POKEMAN SAM
Jul 8, 2004

floWenoL posted:

If you can't figure out how to use Visual Studio, then you have no business programming C++.

That Turkey Story
Mar 30, 2003

If you absolutely hate Visual Studio you can always try Code::Blocks.

But really, just get used to Visual Studio.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Also, Dev-C++ comes with GCC 3.4 and GDB 5.2, which are amazingly out of date. Like, 5 years out of date.

Painless
Jan 9, 2005

Turn ons: frogs, small mammals, piles of compost
Turn offs: large birds, pitchforks
See you at the beach!
I tried dev-c++ something like 5-6 years ago and it was a lovely crash-happy mess. Glad to hear that there are some things you can rely on! Also, it does something weird with GCC options or something because sometimes it just fails to compile code that the same GCC on commandline compiles with no problems.

Whilst farting I
Apr 25, 2006

niteice posted:

Also, Dev-C++ comes with GCC 3.4 and GDB 5.2, which are amazingly out of date. Like, 5 years out of date.

Yeah, I posted some code here a while back and couldn't figure out why it simply wouldn't work and was told that what I had written shouldn't even be compiling - eventually people figured out it was because I was using dev-C++. Its old GCC and GDB really do hurt you in a lot of ways.

Whilst farting I
Apr 25, 2006

I'm trying to do something extremely simple with OpenGL and every tutorial I can find on this is written way beyond my level of understanding and doesn't involve simple shapes. All I want to do is rotate a square (currently on the right side of the screen) around the center of its axis while moving it 40 units to the left until it hits a certain point. I can get it to move, but it's through using a very "hack"ish way of modifying the x-coordinates when I feel like transform might need to be used.

Also please don't mind the name "rect" because it's a square and I'm a bit OCD and don't like to do what would be cosmetic changes until I actually have it semi-functional. :ohdear:

code:
// called whenever the rectangle needs to move
void rectMove()
{
   if (rectStage != RECT_STATIC)
   {
	glBegin(GL_QUADS);
		glColor3f(0.5, 1.0, 0.5);

		glVertex3f(rectX1, 110.0, 0.0);
		glVertex3f(rectX2, 110.0, 0.0);
		glVertex3f(rectX2, 245.0, 0.0);
		glVertex3f(rectX1, 245.0, 0.0);
	glEnd();

	rectX1 += -40.0f;
	rectX2 += -40.0f;
   }

   if (rectX1 && rectX2 < 240)
         rectStage = RECT_STATIC;
}
I've tried some pushing and popping of matrices to use transform and rotate but they just give me an unmoving square. I've also read that I need to shift the object down to the center of where its center would be because it will otherwise shift from a corner? I've tried Red Book, Nehe, and countless other tutorials but nothing clearly explaining any of this - at least how I can understand. :smith:

litghost
May 26, 2004
Builder

Whilst farting I posted:

I'm trying to do something extremely simple with OpenGL and every tutorial I can find on this is written way beyond my level of understanding and doesn't involve simple shapes. All I want to do is rotate a square (currently on the right side of the screen) around the center of its axis while moving it 40 units to the left until it hits a certain point. I can get it to move, but it's through using a very "hack"ish way of modifying the x-coordinates when I feel like transform might need to be used.

Also please don't mind the name "rect" because it's a square and I'm a bit OCD and don't like to do what would be cosmetic changes until I actually have it semi-functional. :ohdear:

code:
// called whenever the rectangle needs to move
void rectMove()
{
   if (rectStage != RECT_STATIC)
   {
	glBegin(GL_QUADS);
		glColor3f(0.5, 1.0, 0.5);

		glVertex3f(rectX1, 110.0, 0.0);
		glVertex3f(rectX2, 110.0, 0.0);
		glVertex3f(rectX2, 245.0, 0.0);
		glVertex3f(rectX1, 245.0, 0.0);
	glEnd();

	rectX1 += -40.0f;
	rectX2 += -40.0f;
   }

   if (rectX1 && rectX2 < 240)
         rectStage = RECT_STATIC;
}
I've tried some pushing and popping of matrices to use transform and rotate but they just give me an unmoving square. I've also read that I need to shift the object down to the center of where its center would be because it will otherwise shift from a corner? I've tried Red Book, Nehe, and countless other tutorials but nothing clearly explaining any of this - at least how I can understand. :smith:

Your problem is you are trying to move the rectangle by changing the statements within you glBegin/glEnd block. This will become a problem when your geometry is nontrival and you end up using display lists or vertex buffers.

You instead want to use glTranslate and glRotate (or glMultMatrix once you know what you are doing) to transform the drawn shape.

This code example assumes the matrix mode is GL_MODELVIEW.

And FYI, my base for testing this code was NeHe Lesson 4. All you need to do is place this within the DrawGLScene().

code:
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

        glPushMatrix(); // Save current matrix
	glLoadIdentity();


	float xpos = 0.5f, ypos = 0.5f, depth = -6.0f;
        float rquad = 0.0f; // Amount to rotate rectangle in degrees

	// Translate within scene
	glTranslatef(xpos,ypos,depth);

	// Rotate at translated position about the normal of the rectangle	
        glRotatef(rquad,0.0f,0.0f,1.0f);


	glColor3f(0.5f,0.5f,1.0f);

	// Draw your object
	glBegin(GL_QUADS);									// Draw A Quad
		glVertex3f(-1.0f, 1.0f, 0.0f);					// Top Left
		glVertex3f( 1.0f, 1.0f, 0.0f);					// Top Right
		glVertex3f( 1.0f,-1.0f, 0.0f);					// Bottom Right
		glVertex3f(-1.0f,-1.0f, 0.0f);					// Bottom Left
	glEnd();											// Done Drawing The Quad

	glPopMatrix(); // Restore matrix state
:edit: More details:

glTranslate is a simple transformation, it effectively moves the draw stuff from the last applied transform to a new location. glTranslate defines what x,y,z mean via the the rotation state, which is modified by glRotate.

glRotate changes the orientation of the coordinate axis of the last applied transformation. glRotate takes 4 arguments. The first is simplest to understand, it is the amount to rotate about in degrees.

The next three arguments define a vector to rotate about. In this example, it rotating about the z axis (ie unit vector [0,0,1]), which happens to be pointing towards the user's eye. However, if you had applied another rotation first, the z-axis of the rotation would be the new z-axis defined by that transformation. However no matter where the final z-axis points, it will be the normal of your rectangle, because the quad is defined in the x-y plane.

litghost fucked around with this message at 01:45 on Mar 21, 2010

functional
Feb 12, 2008

If I have a void * ptr to some data is there a way to distinguish whether it points to mmaped data or malloced data? Will madvise work for this? There is also an int size that represents the number of allocated bytes.

functional fucked around with this message at 02:56 on Mar 21, 2010

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

functional posted:

If I have a void * ptr to some data is there a way to distinguish whether it points to mmaped data or malloced data? Will madvise work for this? There is also an int size that represents the number of allocated bytes.

No. malloc might use mmap behind the scenes.

functional
Feb 12, 2008

ShoulderDaemon posted:

No. malloc might use mmap behind the scenes.

OK. You've pointed out that my question wasn't specific enough. What I actually want to do is safely munmap/free the data. On the manpage munmap is listed as having unspecified behavior when attempting to unmap data that was not originally mmapped. Is this actually true, or is munmap in practice more resilient than free()? The mapped data I am concerned about unmapping will always represent files on disk.

(In some cases I might have control over whether malloc uses mmap. What might change in the above scenarios when this is the case?)

functional fucked around with this message at 03:06 on Mar 21, 2010

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

functional posted:

Is this actually true, or is munmap in practice more resilient than free()? The mapped data I am concerned about unmapping will always represent files on disk.

(In some cases I might have control over whether malloc uses mmap. What might change in the above scenarios when this is the case?)

On at least some systems, brk is implemented behind the scenes as extending an anonymous mapping. If you were to munmap this, you could lose a whole segment of your current executable. On at least some other systems, calling munmap on memory that was not allocated by mmap hits uninitialized values in kernel space, and results in something being unmapped.

There is no portable way to decide how a given pointer was allocated. You have to either track that yourself, or find some other way around your problem.

If you don't care about portability, and you have the size stored separately, you could try poking the internals of your malloc implementation to see if it has an allocation for your address with the same size you think it should have, and use that to decide if you should free or munmap. But that's not exactly sane.

Whilst farting I
Apr 25, 2006

litghost posted:

Your problem is you are trying to move the rectangle by changing the statements within you glBegin/glEnd block. This will become a problem when your geometry is nontrival and you end up using display lists or vertex buffers.

You instead want to use glTranslate and glRotate (or glMultMatrix once you know what you are doing) to transform the drawn shape.

This code example assumes the matrix mode is GL_MODELVIEW.

And FYI, my base for testing this code was NeHe Lesson 4. All you need to do is place this within the DrawGLScene().

code:
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer

        glPushMatrix(); // Save current matrix
	glLoadIdentity();


	float xpos = 0.5f, ypos = 0.5f, depth = -6.0f;
        float rquad = 0.0f; // Amount to rotate rectangle in degrees

	// Translate within scene
	glTranslatef(xpos,ypos,depth);

	// Rotate at translated position about the normal of the rectangle	
        glRotatef(rquad,0.0f,0.0f,1.0f);


	glColor3f(0.5f,0.5f,1.0f);

	// Draw your object
	glBegin(GL_QUADS);									// Draw A Quad
		glVertex3f(-1.0f, 1.0f, 0.0f);					// Top Left
		glVertex3f( 1.0f, 1.0f, 0.0f);					// Top Right
		glVertex3f( 1.0f,-1.0f, 0.0f);					// Bottom Right
		glVertex3f(-1.0f,-1.0f, 0.0f);					// Bottom Left
	glEnd();											// Done Drawing The Quad

	glPopMatrix(); // Restore matrix state
:edit: More details:

glTranslate is a simple transformation, it effectively moves the draw stuff from the last applied transform to a new location. glTranslate defines what x,y,z mean via the the rotation state, which is modified by glRotate.

glRotate changes the orientation of the coordinate axis of the last applied transformation. glRotate takes 4 arguments. The first is simplest to understand, it is the amount to rotate about in degrees.

The next three arguments define a vector to rotate about. In this example, it rotating about the z axis (ie unit vector [0,0,1]), which happens to be pointing towards the user's eye. However, if you had applied another rotation first, the z-axis of the rotation would be the new z-axis defined by that transformation. However no matter where the final z-axis points, it will be the normal of your rectangle, because the quad is defined in the x-y plane.

I tried running Nehe's program 4 and don't understand how it works - its points for the Quad are all 1, but the area is definitely much bigger than 1 pixel. It also does not move, just rotates.

I also don't have a DrawGLScene function - my main contains a glutDisplayFunc(displayFunction), a keyboard function, a time, and a main loop and that's it. This is the content of the display function.

code:
        glClearColor(1.0, 1.0, 1.0, 1.0);   
	glClear(GL_COLOR_BUFFER_BIT);      
	glColor3f(0.0, 0.0, 0.0);			
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();


	drawTemplate();
	drawBoxes();
	powerFunction();					
	rectMove();
 
        glutSwapBuffers();
drawTemplate just draws the screen's template, same with drawBoxes, powerFunction only does something if keys are input - same with rectMove, which activates after the 'd' key has been pressed twice.

Here's what I'm trying and what I understand (I've removed all modifications to rectX1 and rectX2, and this is the entirety of rectMove()):

code:
// called whenever the rectangle needs to move
void rectMove()
{
   // only animate when actually doing something
   if (rectStage != RECT_STATIC)
   {
        // commented out because the entire screen 
        // would go blank whenever it was called
        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	

	glPushMatrix(); // saves the matrix as it is
	glLoadIdentity(); // loads the matrix as it is

        // moves the square 0.5 pixels to the right and up
        // and zoom out at a scale of -6
	glTranslatef(0.5f, 0.5f, -6.0f);

        // rotates on the x axis at -.75 units 
	glRotatef(-0.75f, 0.0f, 0.0f, 1.0f);

		glBegin(GL_QUADS);
			glColor3f(0.5, 1.0, 0.5);
		        glVertex3f(rectX1, 110.0, 0.0);
		        glVertex3f(rectX2, 110.0, 0.0);
		        glVertex3f(rectX2, 245.0, 0.0);
		        glVertex3f(rectX1, 245.0, 0.0);
		glEnd();
	glPopMatrix();
      }
}
I feel like your explanation clarified what these 3 functions do a lot - especially on how glRotate and glTranslate relate, and it's just implementation that I'm missing. I know if I can get it moving I'll understand it a lot better but I can't figure out why it just sits there. :ohdear:

Thank you again to edit to add more info, I had been checking other websites on what those functions do and how the parameters interact and this was by far the most concise and easy to understand information. I really appreciate the effort. :kiddo:

litghost
May 26, 2004
Builder

Whilst farting I posted:


You should learn to read the man pages, see glTranslate, and glRotate.

You also need to realize that the coordinates in OpenGL have no direct relations to pixels except in extremely specific situations, like an orthographic projection with the width and height equal to your view port size. See glOrth. Generally speaking OpenGL coordinates can be united based on physical units if you want (ft, in, m, etc.), or whatever you want. The projection matrix is how you get from model coordinates (your rectangle) to screen coordinates, kind of. I am simplifying this explaination, you can get more details here.

sonic bed head
Dec 18, 2003

this is naturual, baby!
I don't know if this is exactly the right place, but we don't have a real computer architecture thread for my question.

What exactly is g++? I know that it is a compiler. But is it also a linker? Is it also a loader? I'm pretty sure that it is not a loader, but I think that it could be a loader. I am studying for a midterm in computer architecture 1 and this is a question that is coming up when reading through the "Translating and Starting a Program" chapter. I was also under the impression that loading and linking happened at the same time because linking needs to know the exact addresses. Does that mean that bash or the OS takes care of that when you actually type "./a.out"?

Thanks for your help!

covener
Jan 10, 2004

You know, for kids!

sonic bed head posted:

What exactly is g++? I know that it is a compiler. But is it also a linker? Is it also a loader? I'm pretty sure that it is not a loader, but I think that it could be a loader. I am studying for a midterm in computer architecture 1 and this is a question that is coming up when reading through the "Translating and Starting a Program" chapter. I was also under the impression that loading and linking happened at the same time because linking needs to know the exact addresses. Does that mean that bash or the OS takes care of that when you actually type "./a.out"?

It compiles and links, but is not a loader. On linux "man ld.so" explains runtime linking and loading and "man exec" for what happens when you're asking your shell to run an executable.

Whilst farting I
Apr 25, 2006

litghost posted:

You should learn to read the man pages, see glTranslate, and glRotate.

You also need to realize that the coordinates in OpenGL have no direct relations to pixels except in extremely specific situations, like an orthographic projection with the width and height equal to your view port size. See glOrth. Generally speaking OpenGL coordinates can be united based on physical units if you want (ft, in, m, etc.), or whatever you want. The projection matrix is how you get from model coordinates (your rectangle) to screen coordinates, kind of. I am simplifying this explaination, you can get more details here.

I understand how translation and rotation work, I think, now - I just don't understand why my code is not working. It'll be a lot easier for me to understand projection matrices though if I can get it moving besides manually changing the x coordinates of the quad.

For instance, I don't get why this code works, from Red Book chapter 3:

code:
draw_wheel_and_bolts()
{
   long i;

   draw_wheel();
   for(i=0;i<5;i++){
      glPushMatrix();
         glRotatef(72.0*i,0.0,0.0,1.0);
         glTranslatef(3.0,0.0,0.0);
         draw_bolt();
      glPopMatrix();
   }
}
But the code I posted above, which is virtually identical, does not.

code:
// called whenever the rectangle needs to move
void rectMove()
{
   // only animate when actually doing something
   if (rectStage != RECT_STATIC)
   {
        // commented out because the entire screen 
        // would go blank whenever it was called
        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	

	glPushMatrix(); // saves the matrix as it is
	glLoadIdentity(); // loads the matrix as it is

        // moves the square 0.5 pixels to the right and up
        // and zoom out at a scale of -6
	glTranslatef(0.5f, 0.5f, -6.0f);

        // rotates on the x axis at -.75 units 
	glRotatef(-0.75f, 0.0f, 0.0f, 1.0f);

		glBegin(GL_QUADS);
			glColor3f(0.5, 1.0, 0.5);
		        glVertex3f(rectX1, 110.0, 0.0);
		        glVertex3f(rectX2, 110.0, 0.0);
		        glVertex3f(rectX2, 245.0, 0.0);
		        glVertex3f(rectX1, 245.0, 0.0);
		glEnd();
	glPopMatrix();
      }
}

litghost
May 26, 2004
Builder

Whilst farting I posted:


You are going to need to post a compiling example for anyone to diagnose the problem further.
Also, there is a dedicated thread for graphics questions over here, that you might want to move this question too.

haveblue
Aug 15, 2005



Toilet Rascal

Whilst farting I posted:

I understand how translation and rotation work, I think, now - I just don't understand why my code is not working. It'll be a lot easier for me to understand projection matrices though if I can get it moving besides manually changing the x coordinates of the quad.

For instance, I don't get why this code works, from Red Book chapter 3:

code:
draw_wheel_and_bolts()
{
   long i;

   draw_wheel();
   for(i=0;i<5;i++){
      glPushMatrix();
         glRotatef(72.0*i,0.0,0.0,1.0);
         glTranslatef(3.0,0.0,0.0);
         draw_bolt();
      glPopMatrix();
   }
}
But the code I posted above, which is virtually identical, does not.

code:
// called whenever the rectangle needs to move
void rectMove()
{
   // only animate when actually doing something
   if (rectStage != RECT_STATIC)
   {
        // commented out because the entire screen 
        // would go blank whenever it was called
        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	

	glPushMatrix(); // saves the matrix as it is
	glLoadIdentity(); // loads the matrix as it is

        // moves the square 0.5 pixels to the right and up
        // and zoom out at a scale of -6
	glTranslatef(0.5f, 0.5f, -6.0f);

        // rotates on the x axis at -.75 units 
	glRotatef(-0.75f, 0.0f, 0.0f, 1.0f);

		glBegin(GL_QUADS);
			glColor3f(0.5, 1.0, 0.5);
		        glVertex3f(rectX1, 110.0, 0.0);
		        glVertex3f(rectX2, 110.0, 0.0);
		        glVertex3f(rectX2, 245.0, 0.0);
		        glVertex3f(rectX1, 245.0, 0.0);
		glEnd();
	glPopMatrix();
      }
}

-0.75 is a very small amount for a GL rotation; that number is supposed to be in degrees (and see how the example code uses 72 there). A much larger number is needed for the image to noticeably change.

Whilst farting I
Apr 25, 2006

Here's the full file:

http://pastebin.ca/1848509

I'm trying to, upon hitting d a second time, get the square to launch to the left while rotating about its center. I can only get it to move to the left by manually subtracting from the x coordinates, which isn't translation and won't rotate anything.

Removing rectX1 and rectX2 and replacing them with actual numbers does not change the outcome.

I understand that it's a small amount of rotation, the number I had, but I can't get it to move at all - lots of great info has been posted and I hope I can learn from it once I can get the square moving and can play with some numbers a bit more.

Whilst farting I fucked around with this message at 21:59 on Mar 21, 2010

FearIt
Mar 11, 2007
Hello CoC,

I was wondering what the standard way of simulating mouse/keypress inputs would be under Linux (Ubuntu). Is there any Linux version of SendInput or SendMessage?

Edit: NM, xdotool will work fine.

Thank you,
STOP SIGNING YOUR POSTS

Somebody fucked around with this message at 18:34 on Mar 23, 2010

sonic bed head
Dec 18, 2003

this is naturual, baby!

covener posted:

It compiles and links, but is not a loader. On linux "man ld.so" explains runtime linking and loading and "man exec" for what happens when you're asking your shell to run an executable.

Thanks! I had no idea that there were separate programs that did this.

washow
Dec 1, 2007

Here you go, op :toot:
Having a little problem with stuff going out of boundary of my array

http://pastebin.com/SH2ExLqz

It's a homework from my c class and it's supposed to place a Queen randomly and cross out(with x) its possible path. and after crossing out, it's supposed to continuously place queens till the board is filled out. I thought I kinda figured it out but I'm not sure how to limit the for loop so that i does not go out of the boundary.

washow fucked around with this message at 05:43 on Mar 22, 2010

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

What is the problem, specifically? Nobody is going to sit through a 10x10 n-queens solution to just watch it crash (and you're not being consistent with your usage of COL and ROW so I can't modify those values to have it just run on a smaller board). Did you at least run your program through gdb?

edit: that said, your checkDiag function looks pretty fishy; I would highly recommend you start looking there.

Dijkstracula fucked around with this message at 05:59 on Mar 22, 2010

washow
Dec 1, 2007

Here you go, op :toot:
Uhh sorry about that. But what do you mean by my inconsistency with ROW and COL usage? I #defined it up top.

Basically my problem is that diagonally, the Xs go over the boundary so it appears on the next line and stuff. Sometimes it works, and sometimes it just goes downright runtime error and I'm not sure how to make sure that Qs and Xs don't go over the boundaries

E: Oh and am I doing checkNull wrong? Shouldn't it continuously run the program till there is no empty space? if I just leave it like line50 while (checkNull);, the program just hangs.

. Xs appearing in weird spots ugh

washow fucked around with this message at 06:20 on Mar 22, 2010

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

OK, let's look at line 50 since you brought it up. Are you checking whether the return value from calling checkNull() is null, or are you checking whether checkNull is a null function pointer?

if the latter, when would we ever break out of the do { ... } while( <non-zero value>); loop?

Also, this is a problem that compiling with warnings on would have explained:

g++ posted:

lo1-189:~ ntaylor$ g++ -Wall foo.cpp
foo.cpp: In function ‘void populate()’:
foo.cpp:50: warning: the address of ‘bool checkNull(char (*)[10])’ will always evaluate as ‘true’
foo.cpp: In function ‘bool checkNull(char (*)[10])’:
foo.cpp:60: warning: NULL used in arithmetic
foo.cpp: In function ‘void checkSides(char (*)[10], int, int)’:
foo.cpp:72: warning: NULL used in arithmetic
foo.cpp:77: warning: NULL used in arithmetic
foo.cpp: In function ‘void checkDiag(char (*)[10], int, int)’:
foo.cpp:86: warning: NULL used in arithmetic
foo.cpp:89: warning: NULL used in arithmetic
foo.cpp:92: warning: NULL used in arithmetic
foo.cpp:95: warning: NULL used in arithmetic

edit: to answer your ROW/COL inconsistency question, look at line 85. I would would very closely at line 85, particularily if you're trying to track down where you might be walking off the end of an array.

edit: also, you're using rand() to place the queens? :pwn:

Dijkstracula fucked around with this message at 06:36 on Mar 22, 2010

washow
Dec 1, 2007

Here you go, op :toot:
Oh I see that I didn't call the function right.

I'm trying to see if there's an empty space (null) in the array. So if there is a null, return false. And do while loop checks that bool and if it's false, run the program again

E: I know line 85 is wrong and that 10 was just a placeholder. I can't figure it out how to set the condition so that it doesn't go over. Make it COL? And what's wrong with rand() placement :ohdear:

washow fucked around with this message at 06:39 on Mar 22, 2010

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Tell you what, walk through a call to checkDiag() by hand. Take, for instance, i = j = 9. See how long it takes before you start writing to memory outside the array.

You should be able to figure it out from there.

What's wrong with rand() is that your program will run several orders of magnitude longer than it needs to. I mean, I haven't spent much time looking at your code but I would be surprised if it even works correctly.

Dijkstracula fucked around with this message at 06:45 on Mar 22, 2010

washow
Dec 1, 2007

Here you go, op :toot:
All I can figure out is that the z of i < z changes dynamically and I have no idea how to make z so that a[x+z] does not go outside of the boundary. Feeling so dumb right now :saddowns:

Vanadium
Jan 8, 2005

gcc problem!

I am trying to add a constructor overload that only gets chosen for string literals but not for const char* variables, so that those fire a deprecation warning. But apparently the "deprecated" attribute only works for regular constructors and function templates, but not for template constructors.

The idea here is to make my class yell at people who hardcode the strings they instantiate it with, but not people who load them from the proper resource files. Any ideas? :shobon:

code:
struct A {
    template<int N> 
    explicit A(const char(&)[N]) __attribute__((deprecated));
};
template<int N> 
A::A(const char(&)[N]) {}

struct B {
    explicit B(const char*) __attribute__((deprecated));
};
B::B(const char*) {}

template<int N> 
void f(const char(&)[N]) __attribute__((deprecated));
template<int N> 
void f(const char(&)[N]) {}

int main() {
    A a("toot");
    B b("toot");
    f("toot");
}
gcc 4.4.3:
foo.cpp: In function ‘int main()’:
foo.cpp:20: warning: ‘B::B(const char*)’ is deprecated (declared at foo.cpp:11)
foo.cpp:21: warning: ‘void f(const char (&)[N]) [with int N = 5]’ is deprecated (declared at foo.cpp:16)

edit: gcc bugtracker has this listed and suggests a workaround, guess I should have checked there first.

Vanadium fucked around with this message at 20:51 on Mar 23, 2010

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
If you want them to stop doing it, why not just make it not compile?

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

Because I do not want to be responsible for figuring out how to fix the sites where it is currently used.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply