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
EscapeHere
Jan 16, 2005

4VAlien posted:

Check all your array boundaries to make sure you are not referencing outside of arrays (most likely cause). Debug mode gives different machine code so the stack does not look the same and you're not breaking it then. Also, what is the meaning of the non zero return code, it might actually mean something.

Thanks for your help.

Unfortunately that's what's making it so tricky - I can't figure out a way of checking the return code. In Debug it works fine, return code is always 0. In release it's returning non-zero, BUT, if I modify the code to capture and display the error code (for example print to console or a messagebox), that code alone seems to be doing enough to modify that stack that my error code is always 0.

The only way I can think of to find it out would be to do say:

code:
errorcode = RegQueryValueEx(....)
And then somehow examine the stack live and try to see what value errorcode has. But I'm not an experienced programmer to know how to do that. In fact this is my first time using Visual Studio, prior to that all my C++ coding was done with vi and gcc.

Also, I'm new to C++ so apologies if this question sounds stupid, but if I referencing outside an array, wouldn't that cause a segmentation fault and cause Windows to terminate the app?

I'm not getting any sort of crash per se, I'm simply getting a non-zero response to that registry lookup.

Adbot
ADBOT LOVES YOU

4VAlien
Jun 19, 2008
referencing outside the array will not give a crash as long as you're still poking in valid memory (as opposed to a segmentation fault where you try some random address where you don't have access to). I had this in a 3D app once, in Release mode i had a strange artifact on the screen that wasn't there in Debug. I turned out that i was off by one on the array with vector coordinates and that i draw 1 extra triangle that started on my figurine and ended on a corner that was decided by random stack variables.

EscapeHere
Jan 16, 2005
Thanks!

I figured out how to use the Visual Studio disassembly tool to look at the registers on the "jne", and it turns it it's returning error code 234 which is "ERROR_MORE_DATA".

From the docs.

quote:

If the buffer specified by lpData parameter is not large enough to hold the data, the function returns the value ERROR_MORE_DATA, and stores the required buffer size, in bytes, into the variable pointed to by lpcbData. In this case, the contents of the lpValue buffer are undefined.

So, I guess if I increase my buffer size that should fix it. But I don't really understand why I would get this error in Windows 7 (and only in Release, not Debug), but not on any other Windows version.

4VAlien
Jun 19, 2008
What i think :

We learned that Windows 7 is not like other windows :) and returns different data than the previous versions. Therefore the source of the problem only occurs in windows 7 (or is this problem just not showing on different windows versions?).

Debug and Release build can have different ASM (debug won't be optimized etc) therefore an overflow might affect different parts of the stack in different modes and mess with your program in a random different way.

5436
Jul 11, 2003

by astral
Whats the best way to do this.

Say I have an equation, simplicity sake like f(x,y,z) = x*y*z. I want to have a slide bar for each variable. So I can slide x between [0,100], y between [30,50], z between [20,40] and then see how output variable changes. Also have the option of fixing two, and sliding the 3rd and graphing that output. Is this doable in excel or will I have to use matlab?

magicalblender
Sep 29, 2007
implementing slider bars seems simple enough, you shouldn't have any problems there.

Make three option buttons from the same menu you got the slider bar, and link them to a cell. Put the option buttons next to each of the X, Y, and Z cells. Whichever cell is adjacent to the activated option button, consider that one to be the "unfixed" one.

let's define some functions:

g(N) = f(N ,fixed_y,fixed_z)
h(N) = f(fixed_x, N,fixed_z)
i(N) = f(fixed_x,fixed_y, N)
j(N) = g(N) if option button = 1, h(N) if option button = 2, i(N) if option button = 3

...Where fixed_x, fixed_y, and fixed_z are the addresses of your slider-controlled cells.
I guess this is the hard part, because this is just pseudocode so you'll have to figure out an implementation yourself. I'm sure it's possible, although it might be kind of ugly.

Now if you plot j(N) against N, and graph it, you'll get the curve you want. Not sure how you might change the range of N on-the-fly, though.

5436
Jul 11, 2003

by astral
You know where that option is in Office 2007? Can't find it anywhere or in the search.

nm: I found it. It is in the most retarded spot.

5436 fucked around with this message at 06:55 on Aug 13, 2009

BigRedDot
Mar 6, 2008

5436 posted:

Whats the best way to do this.

Say I have an equation, simplicity sake like f(x,y,z) = x*y*z. I want to have a slide bar for each variable. So I can slide x between [0,100], y between [30,50], z between [20,40] and then see how output variable changes. Also have the option of fixing two, and sliding the 3rd and graphing that output. Is this doable in excel or will I have to use matlab?


FWIW I wouldn't define separate functions like above. Unless your mesh size is tiny, just compute the whole cube over the entire 3D domain, then use array slicing operations to get out the single value or 1D or 2D cross sections you want. You can certainly do that in matlab, or I'd probably use numpy/scipy with matplotlib or chaco.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Wasn't sure if this was a C++ problem or a general problem, so sorry if I got it wrong.

I've got a C++ program on a Solaris box that up to now has been compiled as a 32 bit application. I've been instructed to try to get it to compile as 64 bit instead, since we're moving the app to a faster64 bit (ed: whoops) box. Unfortunately, the program requires some shared 32 bit libraries to work, and we don't currently have any way to recompile said libraries.

We're trying to get hold of the source code again, but in the meantime, is there anything I can do to make a 64 bit compile of my application work? Some sort of wrapper or trick I can do so I can at least test things until we get a 64 bit library?

Sorry if this is a stupid question, my knowledge of this phase of assembling an application is weak at best. :(

(edit) Whoops, sorry. This is mostly a "why not, may as well see if it helps performance at all if it's not gonna be an ordeal" sort of thing--I'm not familiar enough with the application in quesiton to answer that.

Ciaphas fucked around with this message at 21:26 on Aug 13, 2009

Avenging Dentist
Oct 1, 2005

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

Ledneh posted:

I've been instructed to try to get it to compile as 64 bit instead, since we're moving the app to a faster box.

I really hope you have a better reason than this.

MrMoo
Sep 14, 2000

Ledneh posted:

We're trying to get hold of the source code again, but in the meantime, is there anything I can do to make a 64 bit compile of my application work? Some sort of wrapper or trick I can do so I can at least test things until we get a 64 bit library?

There is no need at all unless you are moving to IA64.

Scaevolus
Apr 16, 2007

Ledneh posted:


64-bit programs tend to slightly outperform 32-bit programs by about 10% when they do lots of number crunching with large integers or doubles. Otherwise, there's not much benefit to having it 64-bit other than RAM.

Standish
May 21, 2001

64-bit will actually be slower than 32-bit all other things being equal, because 64-bit pointers take up twice the memory and more importantly twice the cache space.

Of course all other things aren't equal because x86-64 has a bunch of extra registers compared to x86-32, but unless you have specific requirements like lots of calculations on numbers > 2^32-1 or working sets > 3GB mentioned above you're probably wasting your time porting to 64-bit. Just run it in 32-bit mode on your 64-bit box.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Standish posted:

unless you have specific requirements like lots of calculations on numbers > 2^32-1 or working sets > 3GB mentioned above you're probably wasting your time porting to 64-bit. Just run it in 32-bit mode on your 64-bit box.

Some operating systems will limit a process to less than the total amount of memory available (often 2gb on recent 32-bit systems), such limits may be higher or nonexistant on 64-bit versions of the same OS

covener
Jan 10, 2004

You know, for kids!

MrMoo posted:

There is no need at all unless you are moving to IA64.

OP is on Solaris. Most scrap Solaris hardware is 64-bit capable.

loinburger
Jul 10, 2004
Sweet Sauce Jones
I'm writing a binary tree traversal function (language is VB6, which is the only language compatible with the accounting software we're using). The treeNode class has a Left and Right field, along with a Siblings field (siblings = multiplicity - 1) and visited field. rootNode is the root of the tree, stackNode is used for going back up the tree since treeNode doesn't have a parent pointer.

When I pop the stack I set Node.Left.visited and Node.Right.visited = 0, but I'm failing to reset the fields properly - on the 164-element test dataset my total visited count is 20 after completing the traversal. (FWIW, without the reset code my total visited count is 164.) I'm evidently popping the stack somewhere without first resetting the Left and Right nodes, but I can't figure out where.
code:
' Returns the next element in a min-to-max traversal
Public Function nextMin(curNode As treeNode) As treeNode
    Dim leftTrav As Boolean     ' Left traversal is valid
    Dim rightTrav As Boolean    ' Right traversal is valid
    leftTrav = False
    rightTrav = False
    If (Not curNode Is Nothing) Then
        If (Not curNode.Left Is Nothing) Then
            If (curNode.Left.visited <= curNode.Left.Siblings) Then
                leftTrav = True
            End If
        End If
        If (Not curNode.Right Is Nothing) Then
            If (curNode.Right.visited <= curNode.Right.Siblings) Then
                rightTrav = True
            End If
        End If
    Else
        If (Not rootNode Is Nothing) Then
            Set stackNode = Nothing
            Set nextMin = nextMin(rootNode)
        End If
        Exit Function
    End If
    
    ' Temp stackNode. stackNode.Right == .dat, .Left == .prev/.peek
    Dim temp As treeNode
    If (leftTrav) Then
        Set temp = New treeNode
        Set temp.Left = stackNode
        Set temp.Right = curNode
        Set stackNode = temp
        Set nextMin = nextMin(curNode.Left)
    ElseIf (curNode.visited <= curNode.Siblings) Then
        curNode.visited = curNode.visited + 1
        Set nextMin = curNode
    ElseIf (rightTrav) Then
        Set temp = New treeNode
        Set temp.Left = stackNode
        Set temp.Right = curNode
        Set stackNode = temp
        Set nextMin = nextMin(curNode.Right)
    Else
        If (Not curNode.Left Is Nothing) Then
            curNode.Left.visited = 0
        End If
        If (Not curNode.Right Is Nothing) Then
            curNode.Right.visited = 0
        End If
        Set temp = stackNode
        Set stackNode = stackNode.Left
        Set nextMin = nextMin(temp.Right)
    End If

End Function

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Your function is spaghetti and I'm not going to bother finding the bug in it.

code:
public class TreeNode
  dim left as TreeNode
  dim right as TreeNode
  ' and whatever payload you want
end class

class TreeNodeStack
  dim head as TreeNode
  dim tail as TreeNodeStack
end class

public class TreeIterator
  dim start as TreeNode  ' initialize this to root
  dim stack as TreeNodeStack

  ' Invariants:
  '  - we haven't visited start or any of its descendents yet
  '  - we haven't visited any of the nodes or right-descendents of any node in the stack
  public function next() as TreeNode
    ' If we don't have a working subtree, look to the stack.
    if start is nothing then
      if stack is nothing then
        next = nothing
        exit function
      end if

      ' Pop something off the stack, visit it, and start on its right subtree next.
      next = stack.head
      start = next.right
      stack = stack.tail
      exit function
    end if

    ' Find the leftmost node in the working subtree, pushing nodes onto the stack as we go.
    while (not start.left is nothing)
      dim newStack as TreeNodeStack = new TreeNodeStack
      newStack.head = start
      newStack.tail = stack
      stack = newStack
      start = start.left
    end while

    ' Return the leftmost node and start on its right subtree next.
    next = start
    start = start.right
  end function
end class

loinburger
Jul 10, 2004
Sweet Sauce Jones
'if-else' statements are spaghetti now?

Avenging Dentist
Oct 1, 2005

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

loinburger posted:

'if-else' statements are spaghetti now?

Spaghetti or not, it's pretty gross.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

loinburger posted:

'if-else' statements are spaghetti now?

You managed to turn a really simple idea (an in-order traversal of a binary tree) into a horrible mess of stateful programming and unnecessary recursion. Basic data structures should not require thought to decipher.

BizarroAzrael
Apr 6, 2006

"That must weigh heavily on your soul. Let me purge it for you."
I would like for a batch file to run an executable and output the text that appears in the prompt to a text file. A typical line I have right now looks like this:

code:
CALL runthis.exe >> output.txt
But this means the output goes into the text file instead of the prompt window, I would like for it to do both, so a user can see what is running without opening the text file. Is it possible to write the output to a file without effecting how the prompt displays?

tef
May 30, 2004

-> some l-system crap ->
is there a tee equivilent in the shell you are using?

BizarroAzrael
Apr 6, 2006

"That must weigh heavily on your soul. Let me purge it for you."

tef posted:

is there a tee equivilent in the shell you are using?

I don't think so, I'm using regular cmd.exe. Plus this isn't just to run on my own machine, and I would rather not have to install new shells on the many computers that might need to use the script.

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.
edit: ugh I'm an illiterate idiot

chocojosh
Jun 9, 2007

D00D.

BizarroAzrael posted:

I would like for a batch file to run an executable and output the text that appears in the prompt to a text file. A typical line I have right now looks like this:

code:
CALL runthis.exe >> output.txt
But this means the output goes into the text file instead of the prompt window, I would like for it to do both, so a user can see what is running without opening the text file. Is it possible to write the output to a file without effecting how the prompt displays?

Not the cleanest, and not tested, but..
CALL runthis.exe > tmpoutput.txt
ECHO tmpoutput.txt
ECHO tmpoutput.txt >> output.txt
DEL tmpoutput.txt

covener
Jan 10, 2004

You know, for kids!

tef posted:

is there a tee equivilent in the shell you are using?

FWIW a native tee.exe is included in http://unxutils.sourceforge.net/.

Not sure it's applicable to cmd.exe, but watch out for changing the exit code of your pipeline with tee.

Mario
Oct 29, 2006
It's-a-me!

chocojosh posted:

Not the cleanest, and not tested, but..
CALL runthis.exe > tmpoutput.txt
ECHO tmpoutput.txt
ECHO tmpoutput.txt >> output.txt
DEL tmpoutput.txt
The echos should be type. tee as mentioned above is much better though.

me your dad
Jul 25, 2006

I got bored today and switched the font on Notepad++ to Inconsolata and now everything looks lovely:

HTML:


CSS:


Does anyone know how to improve the way it appears? Or am I alone in thinking it looks like total poo poo? I can't even remember the settings I had before so I hope I'm not completely hosed.

terminatusx
Jan 27, 2009

:megaman:Indie Game Dev and Bringer of the Apocalypse

Chinaski posted:

Does anyone know how to improve the way it appears?

You're supposed to use the "Consolas" font.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Blurry rear end-text is the worst kind of text.

me your dad
Jul 25, 2006

terminatusx posted:

You're supposed to use the "Consolas" font.

Thanks - I just tried it and it's actually legible.

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.
What did you take those screencaps with?

BizarroAzrael
Apr 6, 2006

"That must weigh heavily on your soul. Let me purge it for you."
Another batch script question. I would like to be able to date stamp the name of a folder the script creates, but telling it:

code:
mkdir dir%date%
Is no good because %date% will have slashes in it (24/08/2009)

Is there another readily-accessible variable that lists the date purely numberically as 240809 or similar?

magicalblender
Sep 29, 2007
You could extract the numbers from %date% like this:
code:
set mm=%date:~4,2%
set dd=%date:~7,2%
set yyyy=%date:~10,4%
mkdir dir%mm%%dd%%yyyy%

me your dad
Jul 25, 2006

Mustach posted:

What did you take those screencaps with?

If you're asking me, FastStone Capture. It's a great program - can do scrolling screenshots, has a drawing mode, editing tools, a color sampling eyedropper (super helpful), and even more amazing poo poo.

It used to be free and it looks like it still might be. Either way it's worth it.

BizarroAzrael
Apr 6, 2006

"That must weigh heavily on your soul. Let me purge it for you."

magicalblender posted:

You could extract the numbers from %date% like this:
code:
set mm=%date:~4,2%
set dd=%date:~7,2%
set yyyy=%date:~10,4%
mkdir dir%mm%%dd%%yyyy%

I found a shorter solution:

code:
FOR /f "tokens=1-3 delims=/ " %%a in ("%date%") DO (set DIR=%%a%%b%%c\)
then make the directory by that name. Comes out DDMMYYYY instead of DDMMYYYY but that's not important, not worth the extra effort of trimming digits from it.

I'm also trying to find a way to check if the current time falls in between two points (specifically 7am and 6pm), and then have it ECHO a warning and PAUSE when it is. So I just need to read the first 2 digits of %time% and see if it is seven or more and 18 or less. Do I still need to use a FOR statement. I'm also not sure of the way to get it to compare integers, or how to do an AND statement (basic stuff I know, but I can't seem to google much of it)

magicalblender
Sep 29, 2007
code:
@set hour=%time:~0,2%
@if %hour% LSS 7 goto normal
@if %hour% GTR 18 goto normal
@echo Warning: Running this script during office hours is a bad idea.
@pause
:normal
@echo Continuing normal operations.
More information on branching, including integer comparison. It doesn't mention anything about an AND operator though, so I don't know if it exists.

Newtie
Dec 4, 2008

For something I'm writing in Fortran I want one possible option to be to break out of the program & spawn a command to the operating system. This seems to be simple enough, it should just be a call to the intrinsic system(). But when I compile my code I'm getting;

code:
undefined reference to `system_'
I'm not sure why this should be coming back as an undefined reference. I'm compiling with gfortran, which is version 4:4.3.3.1-ubuntu1 & my compiler flags are these;

code:
-fno-backslash -fno-automatic -ffixed-form -ffixed-line-length-132 -fmax-errors=100 -std=gnu
I've read that system() is included as an intrinsic in gfortran using the gnu standard. Maybe that's wrong, or it's since been removed? Anybody have any ideas? It's not vitally important to be able to spawn a command to the OS, but it would be nice.

Olly the Otter
Jul 22, 2007
Hmm, it works for me, but I don't have the same version.

code:
$ cat test2.f
      PROGRAM TEST2

      IMPLICIT NONE

      CHARACTER(LEN=*), PARAMETER :: CMD = "ls"

      CALL SYSTEM(CMD)

      END PROGRAM TEST2

$ gfortran -fno-backslash -fno-automatic -ffixed-form -ffixed-line-length-132 -std=gnu -o test2 test2.f
$ ./test2
test2  test2.f
$ gfortran -dumpversion
GNU Fortran (GCC) 4.1.2 20071124 (Red Hat 4.1.2-42)
Copyright (C) 2007 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

Adbot
ADBOT LOVES YOU

stubblyhead
Sep 13, 2007

That is treason, Johnny!

Fun Shoe
Have any of you done any UltraEdit macro writing? I'm having some trouble with one I'm working on, and I'm not sure what the problem is.

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