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
Whilst farting I
Apr 25, 2006

ultra-inquisitor posted:

If you're manually calculating the points using Bresenham, just draw the "pixels" as quads?
code:
float scale = 5;
float halfScale = scale / 2;

glBegin(GL_QUADS);
while (generating_points)
{
	int px = getPointX() * scale;
	int py = getPointY() * scale;

	glVertex2f(px - halfScale, py - halfScale);
	glVertex2f(px + halfScale, py - halfScale); 
	glVertex2f(px + halfScale, py + halfScale);
	glVertex2f(px - halfScale, py + halfScale);
}
glEnd();

Thank you! :neckbeard: You've been a huge help, but I seem to be misunderstanding OpenGL, or Bresenham, or both. :ohdear: Whenever I run this, no matter what I put in for x1,x2,yc1,y2 (yc1 was named as such because Visual Studio complained when I had a variable named y1), it always results in the same thing: the big pixels being drawn from the very bottom left of the window to the very top right.

I tried integrating the optimized algorithm from Wikipedia since I want the code to be robust, but it does betray my understanding of the algorithm a little bit.

http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Optimization

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

	glBegin(GL_QUADS);
	
        while (x1 < x2)
	{
		// checks the slope
		slope = abs(y2-yc1) > abs(x2-x1);

		if (slope)
		{
			swap(x1,yc1);
			swap(x2,y2);
		}

		if (x1 > x2)
		{
			swap(x1,x2);
			swap(yc1,y2);
		}

		// define the points
		dxdy = x2 - x1;
		dydx = abs(y2-yc1);

		// error checking variable as per Wiki
		errorCheck = dxdy/2;

		// decides what action to take with respect to y
		if (yc1 < y2) 
			ystep = 1;
		else 
			ystep = -1;

		px = dxdy * scale;
		py = dydx * scale;

		glVertex2f(px - halfScale, py - halfScale);
		glVertex2f(px + halfScale, py - halfScale); 
		glVertex2f(px + halfScale, py + halfScale);
		glVertex2f(px - halfScale, py + halfScale);

		errorCheck = errorCheck - dydx;         
		
		if (errorCheck < 0)
		{
			yc1 = yc1+ystep;
			errorCheck = errorCheck + dxdy;
		}
	
		// increment x1
		x1 = x1+1;
	}

	glEnd();
	glFlush();
I'm trying to test it with coordinates 100,300,100,300, but no matter what I put in it's always the same: bottom left to top right. I set the Window Size to be 700x700 so it's not that - am I just totally lost on the algorithm?

Adbot
ADBOT LOVES YOU

newsomnuke
Feb 25, 2007

I haven't checked your Bresenham code, but OpenGL does indeed consider bottom left to be the origin, not top left as is usual.

UraniumAnchor
May 21, 2006

Not a walrus.

ultra-inquisitor posted:

I haven't checked your Bresenham code, but OpenGL does indeed consider bottom left to be the origin, not top left as is usual.

Depends on how you set up your projection matrix, it's entirely possible to have the top left be the origin and +Y to be down. Whether that's a good idea is another matter, but it's not difficult.

functional
Feb 12, 2008

I'm statically compiling in a separate malloc which does weird things with dynamically linked functions like strdup that call their own malloc from the library. I know that I can do invasive things like changing LD_PRELOAD to cause strdup to use a different malloc. Is there anything less invasive I can do to cause strdup to rely on my statically linked malloc? Currently I'm just using my own implementation of strdup. In the future I imagine I will encounter situations where I won't be able to use that method.

OddObserver
Apr 3, 2009

functional posted:

I'm statically compiling in a separate malloc which does weird things with dynamically linked functions like strdup that call their own malloc from the library. I know that I can do invasive things like changing LD_PRELOAD to cause strdup to use a different malloc. Is there anything less invasive I can do to cause strdup to rely on my statically linked malloc? Currently I'm just using my own implementation of strdup. In the future I imagine I will encounter situations where I won't be able to use that method.

ELF? It should do it by default, actually, unless you played with visibility (and unless strdup calls a symbol other than malloc). Which is why it's so dangerous to
mess with these.

functional
Feb 12, 2008

OddObserver posted:

ELF? It should do it by default, actually, unless you played with visibility (and unless strdup calls a symbol other than malloc). Which is why it's so dangerous to
mess with these.

I don't understand your post. I am working on a UNIX-compatible system and compiling with gcc. The call free(strdup(str)) always fails contrary to the manual specification. Since I have implemented my own malloc and free this indicates to me that strdup is calling some other malloc. Can you explain what you mean?

OddObserver
Apr 3, 2009

functional posted:

I don't understand your post. I am working on a UNIX-compatible system and compiling with gcc. The call free(strdup(str)) always fails contrary to the manual specification. Since I have implemented my own malloc and free this indicates to me that strdup is calling some other malloc. Can you explain what you mean?

What system in particular?

I mean that normally ELF symbols are global, so there is only a single malloc symbol for the whole program unless you specially try to avoid it. That means that if strdup calls malloc it should call your malloc --- but it might also be calling some sort of __system_malloc or whatever (or the inside-libc calls might be optimized to go directly to the default malloc implementation). There in lies the danger since you could potentially end up with library calling a mixture of the two heap managers.

At any rate, on my Linux machine
code:
void* malloc() {
    abort();
}

int main() {
    strdup("foo");
}
end ups calling my malloc w/o any extra effort.

lol 10 bux
Dec 22, 2004
i <3 (o)(o)s

functional posted:

I'm statically compiling in a separate malloc which does weird things with dynamically linked functions like strdup that call their own malloc from the library. I know that I can do invasive things like changing LD_PRELOAD to cause strdup to use a different malloc. Is there anything less invasive I can do to cause strdup to rely on my statically linked malloc? Currently I'm just using my own implementation of strdup. In the future I imagine I will encounter situations where I won't be able to use that method.

Depending on what you are trying to do, you might be able to get away with the --wrap option to ld. With this you can intercept malloc calls without having to do your own heap management.

ld man page posted:

--wrap=symbol
Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to __wrap_symbol. Any undefined reference to __real_symbol will be resolved to symbol.

This can be used to provide a wrapper for a system function. The wrapper function should be called __wrap_symbol. If it wishes to call the system function, it should call __real_symbol.

Here is a trivial example:

void *
__wrap_malloc (size_t c)
{
printf ("malloc called with %zu\n", c);
return __real_malloc (c);
}


If you link other code with this file using --wrap malloc, then all calls to malloc will call the function __wrap_malloc instead. The call to __real_malloc in __wrap_malloc will call the real malloc function.

You may wish to provide a __real_malloc function as well, so that links without the --wrap option will succeed. If you do this, you should not put the definition of __real_malloc in the same file as __wrap_malloc; if you do, the assembler may resolve the call before the linker has a chance to wrap it to malloc.

Whilst farting I
Apr 25, 2006

ultra-inquisitor posted:

I haven't checked your Bresenham code, but OpenGL does indeed consider bottom left to be the origin, not top left as is usual.

It does that no matter what coordinates I put in there - always bottom left to top right, when I just want it to draw a line segment. :nyoron: How do I get it to draw in the specified locations?

newsomnuke
Feb 25, 2007

Whilst farting I posted:

It does that no matter what coordinates I put in there - always bottom left to top right, when I just want it to draw a line segment. :nyoron: How do I get it to draw in the specified locations?
Looking back at your code, it looks like you are implementing the algorithm wrong. For one thing, much of the code only has to be done once - at the start - but you are doing it for each iteration. Thus variables like errorCheck are being reset when they probably shouldn't be.

Whilst farting I
Apr 25, 2006

ultra-inquisitor posted:

Looking back at your code, it looks like you are implementing the algorithm wrong. For one thing, much of the code only has to be done once - at the start - but you are doing it for each iteration. Thus variables like errorCheck are being reset when they probably shouldn't be.

For some reason, if I don't have the while at the beginning, it only draws the very first pixel. However, I have gotten it working except for drawing straight up or down vertically. How would I accommodate for that? I have a feeling that's the errorCheck variable getting continually reset but I don't know why I'm having trouble with the while loop.

code:
// for all the single xs
while (xBegin < xEnd)
{
	// checks the slope
	slope = abs(yEnd-yBegin) > abs(xEnd-xBegin);

	// if y is bigger, swap out what starts where
	if (slope)
	{
		swap(xBegin,yBegin);
		swap(xEnd,yEnd);
	}

	if (xBegin > xEnd)
	{
		x = xEnd;
		y = yEnd;
		xEnd = xBegin;
	}

	else 
	{
		x = xBegin;
		y = yBegin;
	}

	// define the points
	dx = abs(xEnd-xBegin);
	dy = abs(yEnd-yBegin);

	// error checking variable as per Wiki
	errorCheck = dx/2;
	
	// decides what action to take with respect to y
	if (yBegin < yEnd) 
		ystep = 1;
	else 
		ystep = -1;

	px = x * scale;
	py = y * scale;

	glVertexEndf(px - halfScale, py - halfScale);
	glVertexEndf(px + halfScale, py - halfScale); 
	glVertexEndf(px + halfScale, py + halfScale);
	glVertexEndf(px - halfScale, py + halfScale);

	errorCheck = errorCheck - dy;         
	 
	if (errorCheck < 0)
	{
		y = y + ystep;
		errorCheck = errorCheck + dx;
	}
	
	// increment x and y
	xBegin = xBegin+1;
	yBegin = yBegin+ystep;
}

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->
I decided to make my first GUI program in C++, more to get a handle on the basics of GUI programming than any utilitarian purpose. I decided to go with Qt for this, and I've pretty much got it finished now, but I can't seem to figure out how to compile it so that all dependencies are contained within the .exe to make it portable, instead of having to drop all its dependant DLLs in the executable folder. I tried to follow Qt's guide, but there was an error while mingw32-make was doing its thing, which ended up totally loving up the Qt library, so I couldn't compile any programs at all.

This is the error:
code:
In file included from ../JavaScriptCore/debugger/Debugger.cpp:23:
../JavaScriptCore/debugger/Debugger.h:57: internal compiler error: Segmentation
fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:[url]http://www.mingw.org/bugs.shtml[/url]> for instructions.
mingw32-make[2]: *** [obj/debug/Debugger.o] Error 1
mingw32-make[2]: Leaving directory `c:/Qt/2010.01/qt/src/3rdparty/webkit/WebCore
'
mingw32-make[1]: *** [debug-all] Error 2
mingw32-make[1]: Leaving directory `c:/Qt/2010.01/qt/src/3rdparty/webkit/WebCore
'
mingw32-make: *** [sub-webkit-make_default-ordered] Error 2
and the function from Debugger.h in which the seg fault occurs:
code:
virtual void scriptLoad(QT_PREPEND_NAMESPACE(qint64) id,
                    const UString &program,
                    const UString &fileName, int baseLineNumber)
{
    UNUSED_PARAM(id);
    UNUSED_PARAM(program);
    UNUSED_PARAM(fileName);
    UNUSED_PARAM(baseLineNumber);   <---- Here
};
Could someone help me figure out how to fix the error, or otherwise figure out how to compile everything into one .exe?

Cosmopolitan fucked around with this message at 01:00 on Feb 16, 2010

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Why are you naming the parameters and then trying to outsmart the compiler to tell it you're not using them?

(Also I can just about guarantee that that's not what is segfaulting.)

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->

Avenging Dentist posted:

Why are you naming the parameters and then trying to outsmart the compiler to tell it you're not using them?

(Also I can just about guarantee that that's not what is segfaulting.)

I don't really know what you're talking about, the only steps I took involved copypasting the commands in that Qt guide ("configure -static", and "mingw32-make"). All I know about what's going wrong is I went to the file and line specified, and that's what I pointed out with "<---- Here". I don't know what that file/function is or what it does.

Cosmopolitan fucked around with this message at 01:55 on Feb 16, 2010

Schweinhund
Oct 23, 2004

:derp:   :kayak:                                     
Is there an easier way to write this?

if (times_i_went_to_the_store == 3 ||
times_i_went_to_the_store == 5)
{
do whatever;
}



Is there a way to do:

if (times_i_went_to_the_store == 3 or 5)
{
do whatever;
}

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Schweinhund posted:

Is there an easier way to write this?

if (times_i_went_to_the_store == 3 ||
times_i_went_to_the_store == 5)
{
do whatever;
}



Is there a way to do:

if (times_i_went_to_the_store == 3 or 5)
{
do whatever;
}

code:
if (1 << times_i_went_to_the_store & (1 << 3 | 1 << 5)) { ... }
I do not suggest actually doing this.

The1ManMoshPit
Apr 17, 2005

edit: Wait a minute my terrible goonsay joke wasn't even right dammit. :smith:

The1ManMoshPit fucked around with this message at 05:13 on Feb 16, 2010

Lexical Unit
Sep 16, 2003

code:
#include <cstdio>

int main()
{
	enum
	{
		zero, one, two, three, four, 
		five, six, seven, eight, nine
	};
	
	int times_i_went_to_the_store = zero;
		
	try
	{ 
		do try
		{
			switch (times_i_went_to_the_store)
			{
				case three:
				case five:
					throw 0;
			}
			
			times_i_went_to_the_store++;
		}
		catch (...)
		{
			printf ("do whatever\n");
			throw;
		}
		while (times_i_went_to_the_store != three or 
			times_i_went_to_the_store != five);
		
	}
	catch (...)
	{
	
	}
}
Even if there is a way to write if (i == 3 or i == 5) differently, you probably don't want to because I can't image it would be any more clear and straight forward. If your issue is that you find yourself having to repeatedly type it, then you could just factor it out to a function bool test_if_times_i_went_to_the_store_is_five_or_three(int times_i_went_to_the_store) or something.

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->
I did a mingw32-make confclean and reconfigured it with more options, namely -debug-and-release and -fast, and after a couple of hours of compiling, it gives me another error:

code:
In file included from ../JavaScriptCore/interpreter/Register.h:32,
                 from ../JavaScriptCore/runtime/ArgList.h:25,
                 from ../JavaScriptCore/runtime/JSObject.h:26,
                 from ../JavaScriptCore/runtime/JSArray.h:24,
                 from ../JavaScriptCore/runtime/JSGlobalObject.h:25,
                 from bindings/js/JSDOMGlobalObject.h:30,
                 from bindings/js/JSDOMBinding.h:25,
                 from bindings/js/ScriptState.h:35,
                 from dom/NodeFilterCondition.h:28,
                 from dom/NodeFilter.h:28,
                 from dom/NodeFilter.cpp:26:
../JavaScriptCore/runtime/JSValue.h: In function `JSC::JSValue JSC::jsNull()':
../JavaScriptCore/runtime/JSValue.h:269: internal compiler error: Segmentation f
ault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:[url]http://www.mingw.org/bugs.shtml[/url]> for instructions.
mingw32-make[4]: *** [obj/debug/NodeFilter.o] Error 1
mingw32-make[4]: Leaving directory `c:/Qt/2010.01/qt/src/3rdparty/webkit/WebCore
'
mingw32-make[3]: *** [debug-all] Error 2
mingw32-make[3]: Leaving directory `c:/Qt/2010.01/qt/src/3rdparty/webkit/WebCore
'
mingw32-make[2]: *** [all] Error 2
mingw32-make[2]: Leaving directory `c:/Qt/2010.01/qt/src/3rdparty/webkit/WebCore
'
mingw32-make[1]: *** [sub-webkit-make_default-ordered] Error 2
mingw32-make[1]: Leaving directory `C:/Qt/2010.01/qt'
mingw32-make: *** [all] Error 2
This is getting really frustrating.

OddObserver
Apr 3, 2009

Anunnaki posted:

This is getting really frustrating.

The compiler is crashing. I'd suggest checking for updates, as well as running a memory test and making sure your machine isn't overheating.

Edit: also, independent of that, if you have decent broadband you could just grab binaries for Qt-on-mingw -- no need to build the library yourself:
http://qt.nokia.com/downloads/sdk-windows-cpp

OddObserver fucked around with this message at 07:14 on Feb 16, 2010

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->

OddObserver posted:

The compiler is crashing. I'd suggest checking for updates, as well as running a memory test and making sure your machine isn't overheating.

Edit: also, independent of that, if you have decent broadband you could just grab binaries for Qt-on-mingw -- no need to build the library yourself:
http://qt.nokia.com/downloads/sdk-windows-cpp

Everything's up-to-date, and I don't think I'm having heat issues; my CPU never goes above 50 C and I game regularly, and have had no BSODs or any instability.

The Qt installer installs the shared library, and I haven't been able to find a prebuilt static Qt library.

Zorn
Oct 24, 2000
code:
    static const int times[] = {3, 5};
    static const int * const times_end = &times[sizeof(times)/sizeof(times[0])];

    if(std::find(&times[0], times_end, times_i_went_to_the_store) != times_end)
    {
        //Yep
    }
    else
    {
        //Nope        
    }

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Anunnaki posted:

The Qt installer installs the shared library, and I haven't been able to find a prebuilt static Qt library.
Are you being forced to distribute this as a "standalone" executable? If not, just link dynamically because nobody worth giving it to is going to cry if you give them a zip file or an installer instead of a huge-rear end exe.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Schweinhund posted:

Is there an easier way to write this?

if (times_i_went_to_the_store == 3 ||
times_i_went_to_the_store == 5)
{
do whatever;
}



Is there a way to do:

if (times_i_went_to_the_store == 3 or 5)
{
do whatever;
}

From a post I made in the Coding Horrors thread a while back. Paste this into, I dunno, "membership.h":

code:
// Forward declaration
template <typename... Values>
class any_of_comparator;

// Base case
template <typename First>
class any_of_comparator<First>
{
private:
	const First& first;
	
public:
	any_of_comparator(const First& _f) : first(_f) { }
	
	template <typename T>
	bool not_contains(const T& value) const
	{
		return value != first;
	}

	template <typename T>
	bool contains(const T& value) const
	{
		return value == first;
	}
};

// Recursive case
template <typename First, typename... Rest>
class any_of_comparator<First, Rest...> : private any_of_comparator<Rest...>
{
private:
	const First& first;

public:
	any_of_comparator(const First& _f, const Rest&... _r) :
		first(_f), any_of_comparator<Rest...>(_r...)
	{
	}

	template <typename T>
	bool not_contains(const T& value) const
	{
		return (value != first) && any_of_comparator<Rest...>::not_contains(value);
	}

	template <typename T>
	bool contains(const T& value) const
	{
		return (value == first) || any_of_comparator<Rest...>::contains(value);
	}
};

// The functional form is required so that the compiler will deduce the template types
// (which it won't do if we left this out and tried to use the constructor for the
// above class instead)
template <typename... Values>
any_of_comparator<Values...> any_of(const Values&... values)
{
	return any_of_comparator<Values...>(values...);
}

template <typename T, typename... Values>
bool operator==(const T& lhs, const any_of_comparator<Values...>& rhs)
{
	return rhs.contains(lhs);
}

template <typename T, typename... Values>
bool operator!=(const T& lhs, const any_of_comparator<Values...>& rhs)
{
	return rhs.not_contains(lhs);
}
And then include "membership.h" and use it like this:

code:
if (times_i_went_to_the_store == any_of(3, 5))
{
do whatever;
}
The only catch is you'll need a compiler that supports C++0x :v:

Mr.Mojo
Sep 11, 2001

Nascita di Venere
edit: nvm

Mr.Mojo fucked around with this message at 14:44 on Feb 16, 2010

newsomnuke
Feb 25, 2007

Whilst farting I posted:

For some reason, if I don't have the while at the beginning, it only draws the very first pixel. However, I have gotten it working except for drawing straight up or down vertically. How would I accommodate for that? I have a feeling that's the errorCheck variable getting continually reset but I don't know why I'm having trouble with the while loop.
Your problems are because you're flipping the x/y in the slope check but not updating the while loop to reflect that you're testing against y instead of x. There may well be other issues. Really, do it like the example code.

Zhentar
Sep 28, 2003

Brilliant Master Genius

Anunnaki posted:

mingw32-make

mingw is a poor choice for static linking (and every other situation in which you aren't forced to use it). Use msvc instead.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
What? There's nothing wrong with MinGW (except that it uses GCC, but when you're comparing that to MSVC, it's basically a wash).

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.

Schweinhund posted:

Is there an easier way to write this?

if (times_i_went_to_the_store == 3 ||
times_i_went_to_the_store == 5)
{
do whatever;
}

code:
switch(times_i_went_to_the_store) {
  case 3:
  case 5:
    do whatever;
}

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->

Mustach posted:

Are you being forced to distribute this as a "standalone" executable? If not, just link dynamically because nobody worth giving it to is going to cry if you give them a zip file or an installer instead of a huge-rear end exe.

Well, just having to distribute the DLLs with the .exe really isn't the problem so much as keeping track of which ones I need to distribute with it. When I tried sending my friend the .exe, I copied all the DLLs in the release folder, but he got an error about another missing DLL, which I had to find and send to him for it to work.

Also, genuine question, what's wrong with GCC, compared to MSVC? The free version of Qt only comes with MinGW, so I'm stuck with that in any case.

Vanadium
Jan 8, 2005

As I posted in the Coding Horrors thread a while ago~

Vanadium posted:

I got pretty much as far, except I did the recursion by composition and not inheritance, but then I tried to wrap boost::call_traits<T>::param_type around everything to avoid needless copying and it all fell apart. :(

Edit: I guess they just gently caress with argument deduction. How does this perfect forwarding thing work again...

Any ideas how to make it require less copying?

code:
#include <iostream>
#include <string>

template<typename... ArgsT>
struct any_impl;

template<typename FirstT>
struct any_impl<FirstT> {
  any_impl(FirstT first) : first(first) {}

  FirstT first;
};

template<typename FirstT, typename... OtherTs>
struct any_impl<FirstT, OtherTs...> {
  any_impl(FirstT first, OtherTs... others)
    : first(first), others(others...) {}

  FirstT first;
  any_impl<OtherTs...> others;
};

template<typename T, typename AnyT>
bool operator==(T obj, const any_impl<AnyT>& any) {
  return obj == any.first;
}

template<typename T, typename FirstT, typename... OtherTs>
bool operator==(T obj, const any_impl<FirstT, OtherTs...>& any) {
  return obj == any.first || obj == any.others;
}

template<typename T, typename AnyT>
bool operator==(const any_impl<AnyT>& any, T obj) {
  return obj == any.first;
}

template<typename T, typename FirstT, typename... OtherTs>
bool operator==(const any_impl<FirstT, OtherTs...>& any, T obj) {
  return any.first == obj || any.others == obj;
}

template<typename... ArgTs>
any_impl<ArgTs...> any_of(ArgTs... args) {
  return any_impl<ArgTs...>(args...);
}

// "trace" copying
template<typename T>
struct verbose {
  verbose(T val) : val(val) {
    std::cout << " verbose( " << val << " )" << std::endl;
  }

  verbose(const verbose& other) : val(other.val) {
    std::cout << " verbose([" << val << "])" << std::endl;
  }

  ~verbose() {
    std::cout << "~verbose( " << val << " )" << std::endl;
  }

  bool operator==(const verbose& other) const {
    std::cout
      << " verbose( " << val << " ) == verbose( "
      << other.val << " )" << std::endl;
    return val == other.val;
  }

  T val;
};

int main() {
  if (any_of(4, 3, 2, 1) == 1)
    std::cout << "yay" << std::endl;

  if (std::string("foo") == any_of("foo", "bar", "baz"))
    std::cout << "yay 2" << std::endl;

  verbose<int> v1(1), v2(2), v3(3), v4(4);
  if (any_of(v1, v2, v3, v4) == verbose<int>(5))
    std::cout << "yay 3" << std::endl;
}

vvv whoops how did I miss that

Vanadium fucked around with this message at 22:45 on Feb 16, 2010

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Anunnaki posted:

Well, just having to distribute the DLLs with the .exe really isn't the problem so much as keeping track of which ones I need to distribute with it. When I tried sending my friend the .exe, I copied all the DLLs in the release folder, but he got an error about another missing DLL, which I had to find and send to him for it to work.
Dependency Walker solves this problem.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Vanadium posted:

As I posted in the Coding Horrors thread a while ago~

Scroll up a few posts, bub :colbert:

Cosmopolitan
Apr 20, 2007

Rard sele this wai -->

Mustach posted:

Dependency Walker solves this problem.

Wonderful, thanks. :)

Zhentar
Sep 28, 2003

Brilliant Master Genius

Anunnaki posted:

Also, genuine question, what's wrong with GCC, compared to MSVC? The free version of Qt only comes with MinGW, so I'm stuck with that in any case.

When it comes to statically compiling Qt, there are two problems:
1. You can't statically link mingwm10.dll, which is a dependency for Qt unless you remove some -mthreads options from the Qt build. The official position on this, last I checked, was that this doesn't appear to make things go horribly wrong so it might be okay.
2. It doesn't do dead-code removal. This will likely result in a compiled binary twice as large as compared to MSVC.


Qt free version has supported MSVC since one of the 4.3 versions, which came out two years ago. You can download the visual studio Express Edition free from Microsoft.

ctz
Feb 6, 2003

Zhentar posted:

2. It doesn't do dead-code removal. This will likely result in a compiled binary twice as large as compared to MSVC.

It certainly does do dead-code removal. I think you're referring to link-time optimisation (a distinct, related feature) which was only recently implemented and hasn't found its way into a stable release yet. Both have been implemented in CL for quite a while now.

Goreld
May 8, 2002

"Identity Crisis" MurdererWild Guess Bizarro #1Bizarro"Me am first one I suspect!"

Whilst farting I posted:

For some reason, if I don't have the while at the beginning, it only draws the very first pixel. However, I have gotten it working except for drawing straight up or down vertically. How would I accommodate for that? I have a feeling that's the errorCheck variable getting continually reset but I don't know why I'm having trouble with the while loop.

code:
// for all the single xs
while (xBegin < xEnd)
{
	[b]THIS CODE DOES NOT BELONG IN THE LOOP
        // checks the slope
	slope = abs(yEnd-yBegin) > abs(xEnd-xBegin);

	// if y is bigger, swap out what starts where
	if (slope)
	{
		swap(xBegin,yBegin);
		swap(xEnd,yEnd);
	}

	if (xBegin > xEnd)
	{
		x = xEnd;
		y = yEnd;
		xEnd = xBegin;
	}

	else 
	{
		x = xBegin;
		y = yBegin;
	}
        END BAD NONO SECTION[/b]

	
}

You put the swaps in the loop. Bad graphics student, bad!

Check for swaps and determine your xbegin/end/ybegin/end before you go through the loop.

As a good practice in graphics, your drawing parameter (xbegin/end) shouldn't be used to iterate through the data. You need another variable, ie. x, tx, i, j, whatever to iterate through. The begin/end's should be treated as consts. In later graphics applications you're going to have to treat stuff like that as consts if you want to implement splines.

Whenever you're iterating through an algorithm like that, you shouldn't alter the original drawing parameters. Otherwise it'll cause you a world of hurt if you do anything complex or attempt to vectorize stuff (like for the GPU).


edit: yes I realize the wikipedia entry does swapping, but there's other ways to do it that are safer. Not to mention that as soon as you get into anything even remotely more complex, especially raytracing, you can cause a shitload of problems doing potentially unsafe swaps.

Goreld fucked around with this message at 01:20 on Feb 19, 2010

DeciusMagnus
Mar 16, 2004

Seven times five
They were livin' creatures
Watch 'em come to life
Right before your eyes
Quick C question. What does the following declare?
code:
double (*d)[16];
The only time I've seen (*identifier) is declaring a pointer to a function. I thought that parentheses were treated specially in variable declarations. MSC interprets it as a pointer to 16 doubles (or in it's own words a double(*)[16]). I guess I've never seen syntax like that before, so what do parentheses do in variable declarations (that aren't pointers to functions)? Ordering?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

DeciusMagnus posted:

Quick C question. What does the following declare?
code:
double (*d)[16];
The only time I've seen (*identifier) is declaring a pointer to a function. I thought that parentheses were treated specially in variable declarations. MSC interprets it as a pointer to 16 doubles (or in it's own words a double(*)[16]). I guess I've never seen syntax like that before, so what do parentheses do in variable declarations (that aren't pointers to functions)? Ordering?

Declarators are read inside-out, and you can parenthesize arbitrary declarators to specify grouping. So, e.g., int id; and int (id); are equivalent, and you can write things like:

code:
int *(*(id[10]))[20]

        id           # id
          [10]       # is an array of 10
       (      )      # (these don't do anything)
      *              # pointers
     (         )     # (these make the star bind inside the next array)
                [20] # to an array of 20
    *                # pointers
int                  # to int
EDIT: Right, and like mr_jim says, the suffixes bind tighter than the prefixes (just like they do in expressions).

rjmccall fucked around with this message at 22:28 on Feb 19, 2010

Adbot
ADBOT LOVES YOU

mr_jim
Oct 30, 2006

OUT OF THE DARK

DeciusMagnus posted:

Quick C question. What does the following declare?
code:
double (*d)[16];
The only time I've seen (*identifier) is declaring a pointer to a function. I thought that parentheses were treated specially in variable declarations. MSC interprets it as a pointer to 16 doubles (or in it's own words a double(*)[16]). I guess I've never seen syntax like that before, so what do parentheses do in variable declarations (that aren't pointers to functions)? Ordering?

I think the parenthesis are there because [] binds more tightly than * does:

code:
double (*d)[16];  // a pointer to an array of 16 doubles
double *d[16];    // an a array of 16 pointers to doubles
I might be wrong about that though. C's precedence rules are screwy, but there's nothing special about parenthesis in variable declarations. They're just used to specify precedence.

Edit: rjmccall explained it a bit better. See K&R Section 5.12 on Complicated Declarations.

mr_jim fucked around with this message at 22:26 on Feb 19, 2010

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