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
Stephen
Feb 6, 2004

Stoned
Nice, thanks guys. I wasn't even sure where to begin.

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

csammis posted:

Looks like someone got his Cheerios pissed in on the wrong side of the bed this morning :shobon:

:v:

If you know how to edit a file with a space in it, i.e. adding quotes you would do the same with other commands that gently caress up. It just seems a lot longer to find about a -d parameter than to use quotes wrapped around the URL.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I just get pissy when I go into a thread that's about asking questions and get shat on. Maybe my question was from a dumb mistake, who knows?

MrMoo
Sep 14, 2000

Rocko Bonaparte posted:

I just get pissy when I go into a thread that's about asking questions and get shat on.

:haw: It's not a programming question either.

It was a lovely retort though, I apologise, I updated it to something slightly less antagonistic.

Vivian Darkbloom
Jul 14, 2004


MATLAB, the engineer's reasonable language where everything makes sense

code:
function butts
global foo
foo = 'qwerty';
helper()

function helper
sprintf(foo)  %% error: "Undefined function or variable 'foo'."
What the gently caress is global for if it doesn't work for sub-functions? Why does the Mathworks hate me so much?

Vanadium
Jan 8, 2005

My intuition says you have so say "global foo" in the subfuction, but I never used matlab, sorry. I am not an engineer. :(

Vivian Darkbloom
Jul 14, 2004


Vanadium posted:

My intuition says you have so say "global foo" in the subfuction, but I never used matlab, sorry. I am not an engineer. :(

Thanks, that works. I've abandoned any search for reason or consistency in Matlab - I'm just glad to get the drat thing working.

chocojosh
Jun 9, 2007

D00D.

Vivian Darkbloom posted:

Thanks, that works. I've abandoned any search for reason or consistency in Matlab - I'm just glad to get the drat thing working.

I've not used Matlab myself but there are other languages that require you to declare which global variables you are using. I like it because it lets you have global variables while still having some minimal control over where they're modified (do a search for global <varname>).

Nam Taf
Jun 25, 2005

I am Fat Man, hear me roar!

Vivian Darkbloom posted:

Thanks, that works. I've abandoned any search for reason or consistency in Matlab - I'm just glad to get the drat thing working.

Matlab is faultless and I will have none of this talk about my beloved language! :colbert:

IIRC, you declare your global variables in both the subfunction and main function.

('help global' in the workspace :ssh: )

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane
Stupid question about QuickSort: I understand why most of the algorithm works, but I'm confused as to swapping the pivot element at the end with whatever the last unsorted element is. If the pivot is greater than all other elements being sorted, wouldn't this result in the algorithm giving an incorrect result? Yet none of the pseudocode implementations I've seen check to make sure this is not the case.

Is there something obvious I'm overlooking?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

PT6A posted:

Stupid question about QuickSort: I understand why most of the algorithm works, but I'm confused as to swapping the pivot element at the end with whatever the last unsorted element is. If the pivot is greater than all other elements being sorted, wouldn't this result in the algorithm giving an incorrect result? Yet none of the pseudocode implementations I've seen check to make sure this is not the case.

I assume you're talking about the last step in the in-place partition phase; Wikipedia gives representative pseudocode for this:
code:
function partition(array, left, right, pivotIndex)
     pivotValue := array[pivotIndex]
     swap array[pivotIndex] and array[right] // Move pivot to end
     storeIndex := left
     for i  from  left to right &#8722; 1
         if array[i] &#8804; pivotValue 
             swap array[i] and array[storeIndex]
             storeIndex := storeIndex + 1
     swap array[storeIndex] and array[right] // Move pivot to its final place
     return storeIndex
The check you suggest is unnecessary because storeIndex will be exactly equal to right in that case, so the swap will be a no-op.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

rjmccall posted:

I assume you're talking about the last step in the in-place partition phase; Wikipedia gives representative pseudocode for this:
code:
function partition(array, left, right, pivotIndex)
     pivotValue := array[pivotIndex]
     swap array[pivotIndex] and array[right] // Move pivot to end
     storeIndex := left
     for i  from  left to right &#8722; 1
         if array[i] &#8804; pivotValue 
             swap array[i] and array[storeIndex]
             storeIndex := storeIndex + 1
     swap array[storeIndex] and array[right] // Move pivot to its final place
     return storeIndex
The check you suggest is unnecessary because storeIndex will be exactly equal to right in that case, so the swap will be a no-op.

Yep, I see it now. I was actually working off my professor's pseudocode, but it's quite similar. I didn't notice that storeIndex gets incremented past (right - 1).

It all makes sense now, thanks.

POKEMAN SAM
Jul 8, 2004
How easy would it be to write something that reads in well-formed XML and writes it back out with certain stylistic points (such as if it has more than 3 attributes, put them each one one line) or alphabetize the attributes, etc.. I'm open to languages, but it seems like C# would be suited to do this, I just want to know if I'm biting off more than I chew if I start this. (This would be to clean up some XML files I hand-wrote. There's no Serializer for it or anything, I read in the XML ignorant of the styling and I never have the application write it back out.)

hexadecimal
Nov 23, 2008

by Fragmaster

Ugg boots posted:

How easy would it be to write something that reads in well-formed XML and writes it back out with certain stylistic points (such as if it has more than 3 attributes, put them each one one line) or alphabetize the attributes, etc.. I'm open to languages, but it seems like C# would be suited to do this, I just want to know if I'm biting off more than I chew if I start this. (This would be to clean up some XML files I hand-wrote. There's no Serializer for it or anything, I read in the XML ignorant of the styling and I never have the application write it back out.)

I am not well versed in C# but if i was to do this, I would use lex/yacc. I am pretty sure C# supports regular expression matching with its standard API, so lexer part is done. You should look into C# compiler/compiler, or just make your own parser, then parse in XML and spit it back out in whatever format you want. This is probably at least a few days worth of work.

POKEMAN SAM
Jul 8, 2004

hexadecimal posted:

I am not well versed in C# but if i was to do this, I would use lex/yacc. I am pretty sure C# supports regular expression matching with its standard API, so lexer part is done. You should look into C# compiler/compiler, or just make your own parser, then parse in XML and spit it back out in whatever format you want. This is probably at least a few days worth of work.

This sounds like overkill; I swear there has to be a better/smarter way to do this.

DLCinferno
Feb 22, 2003

Happy

Ugg boots posted:

This sounds like overkill; I swear there has to be a better/smarter way to do this.
There is, and using C# would be extremely easy to do this. It's simple to read in XML and then have an in-memory XML document to work with, either iterating the nodes or using xpath queries or something.

Assuming you already are familiar with XML (like understand what an attribute is) and you already know how to program in a C-type language it shouldn't be hard at all.

Look up System.Xml.XmlDocument and XmlReader.

POKEMAN SAM
Jul 8, 2004

DLCinferno posted:

Look up System.Xml.XmlDocument and XmlReader.

I'm familiar with a lot of what C# has to offer, just my exposure to XML programming has been quite limited. It looks like System.Xml.XmlTextReader will help me, since I can read in an XML document and just iterate through the document. Instead of writing the document out with an XML Writer, though, I will probably just write it all out to disk by hand, so I can format it. Then the only thing that I need to be careful of is that I don't accidentally clobber anything, but a diff tool should help with that.

Edit: There's nothing in the XLinq suite that I could use to make this easier, is there?

floWenoL
Oct 23, 2002

hexadecimal posted:

I am not well versed in C# but if i was to do this, I would use lex/yacc. I am pretty sure C# supports regular expression matching with its standard API, so lexer part is done. You should look into C# compiler/compiler, or just make your own parser, then parse in XML and spit it back out in whatever format you want. This is probably at least a few days worth of work.

It is becoming clear that whenever someone asks a question, whatever hexadecimal suggests is almost certainly what you don't want to do.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

hexadecimal posted:

I am not well versed in C# but if i was to do this, I would use lex/yacc. I am pretty sure C# supports regular expression matching with its standard API, so lexer part is done. You should look into C# compiler/compiler, or just make your own parser, then parse in XML and spit it back out in whatever format you want. This is probably at least a few days worth of work.

Shine on you crazy diamond

yippee cahier
Mar 28, 2005

there's a toprettyxml function for objects returned by python's xml.dom.minidom module:
code:
from xml.dom.minidom import parse

print( parse('xmlfile.xml').toprettyxml() )

POKEMAN SAM
Jul 8, 2004

sund posted:

there's a toprettyxml function for objects returned by python's xml.dom.minidom module:
code:
from xml.dom.minidom import parse

print( parse('xmlfile.xml').toprettyxml() )

It's so crazy I must try it!

Edit: That worked awesome to put the XML into a standard prettified format. I could definitely take the output of this, and knowing for example that each element (or close tag) is on its own line, take each line/element and format it how I want it.

Thanks!

POKEMAN SAM fucked around with this message at 08:33 on Dec 11, 2008

tef
May 30, 2004

-> some l-system crap ->
There is always something like xslt

6174
Dec 4, 2004
My brain is being dense right now and I'm having problems getting gfortran to link to a library.

I know that I have the library I'm trying to link to:
/usr/lib/liblapack.so.3.0 (has a symlink pointing to it at /usr/lib/liblapack.so.3)

It successfully links if I do the following:

gfortran -o program /usr/lib/liblapack.so.3 filename1.o filename2.o ....

I am used to linking to a library by using -l, so something like

gfortran -o program -llapack filename1.o ...

(potentially with the -llapack at a different location on the line, I normally let a build system take care of this so I don't remember the exact placement)

However this second version always produces the following error:

/usr/bin/ld: cannot find -llapack

I'm using 64-bit Ubuntu Linux, ld 2.18, gfortran 4.2.1, and LAPACK comes from the packages lapack3.

What do I need to do to get so that I don't need to specify an absolute path to the library? The program is normally built with GNU Make and built on lots of different systems so relying on an absolute path for a library isn't an option.

No Safe Word
Feb 26, 2005

6174 posted:

My brain is being dense right now and I'm having problems getting gfortran to link to a library.

I know that I have the library I'm trying to link to:
/usr/lib/liblapack.so.3.0 (has a symlink pointing to it at /usr/lib/liblapack.so.3)

It successfully links if I do the following:

gfortran -o program /usr/lib/liblapack.so.3 filename1.o filename2.o ....

I am used to linking to a library by using -l, so something like

gfortran -o program -llapack filename1.o ...

(potentially with the -llapack at a different location on the line, I normally let a build system take care of this so I don't remember the exact placement)

However this second version always produces the following error:

/usr/bin/ld: cannot find -llapack

I'm using 64-bit Ubuntu Linux, ld 2.18, gfortran 4.2.1, and LAPACK comes from the packages lapack3.

What do I need to do to get so that I don't need to specify an absolute path to the library? The program is normally built with GNU Make and built on lots of different systems so relying on an absolute path for a library isn't an option.

If it's anything like gcc/g++ you just need to put the library path after a -L option:
code:
gfortran -o program -llapack -L/path/to/directory/with/lapack/ filename1.o

6174
Dec 4, 2004

No Safe Word posted:

If it's anything like gcc/g++ you just need to put the library path after a -L option:
code:
gfortran -o program -llapack -L/path/to/directory/with/lapack/ filename1.o

gfortran is very much like gcc/g++ since it is also part of the GNU Compiler Collection (The gfortran info page even tells you to read the gcc info page for the language independent options). However I still get the error.
code:
$ gfortran -o program -llapack -L/usr/lib/ filename1.o filename2.o ...
/usr/bin/ld: cannot find -llapack
collect2: ld returned 1 exit status
$ 
And in /usr/lib is liblapack.so.3, so that should work, assuming I understand you.

simux
Oct 18, 2007
Rara Avis
Try symlinking liblapack.so to liblapack.so.3. I seem to remember that ld only maps -lfile to libfile.so. I could be wrong but that's the first thing I'd try.

6174
Dec 4, 2004

simux posted:

Try symlinking liblapack.so to liblapack.so.3. I seem to remember that ld only maps -lfile to libfile.so. I could be wrong but that's the first thing I'd try.

That works. It allows just -llapack to find the library.

This brings up a related question. If ld simply maps -lfile to libfile.so, then why is it that quite a few of the libraries I've got in /usr/lib do not have a .so variant? Many of them are named libfile.so.# for some number #. But there are also quite a few that have a .so symlinked to the .so.# version. Presumably with as many libraries that have this, the Ubuntu packagers didn't botch this many packages, so I'm missing something. I do see that if I run ldd on the executable, it points to liblapack.so.3. Does this mean that a .so symlink is only needed if you are linking to a specific library, and since most people aren't doing that (at least using ld), the .so symlink isn't needed and thus the package maintainers don't put it in?

floWenoL
Oct 23, 2002

6174 posted:

That works. It allows just -llapack to find the library.

This brings up a related question. If ld simply maps -lfile to libfile.so, then why is it that quite a few of the libraries I've got in /usr/lib do not have a .so variant? Many of them are named libfile.so.# for some number #. But there are also quite a few that have a .so symlinked to the .so.# version. Presumably with as many libraries that have this, the Ubuntu packagers didn't botch this many packages, so I'm missing something. I do see that if I run ldd on the executable, it points to liblapack.so.3. Does this mean that a .so symlink is only needed if you are linking to a specific library, and since most people aren't doing that (at least using ld), the .so symlink isn't needed and thus the package maintainers don't put it in?

It's been a while since I've worked with Linux packaging, but I believe you won't get the symlinks unless you have the package <FOO>-dev (or similar) installed.

jimbroof
Sep 4, 2003

my wife drew this for me :]
So i'm working on this C# project for work, and I'm just starting to seriously use inheritance for the first time. I have a base class that does x, y, and z, and I want another object that does x, y, z, AND w. It seems clunky to include w in the base, so I made this derived class. The only constructor in the derived class takes a base-class object as a parameter, since it will be performing additional processing on everything that object controls. Here is an outline of what I've got:

code:

class Base
{
   Base(Base baseObject)
   {
      //standard copy constructor
   }
   
   //x,y,z methods
}

class Derived : Base  
{
   Derived(Base baseObject)
      : base(baseObject)
   {
      //initialize some Derived-only stuff
   }

   //w method
}
During my last code review, one of our coders said this was a bad idea, as inheritance should only move up. But the derived class is really just a decorated version of the base class, as it will use pretty much all of base's protected methods and then add a couple of its own. Is it really bad design to do this? Should I just merge the derived class up into the base class, or is supplying a Base object into a Derived constructor acceptable from an architecture standpoint?

jimbroof fucked around with this message at 07:21 on Dec 12, 2008

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
It's a bad design, but not for the reason your coworkers are saying (and I'm not really even sure they're saying anything that makes sense at all). Inheritance is an "is-a" relationship, e.g. a Ford is-a kind of Car. A vector in R4 is not a kind of vector in R3, so you shouldn't be using inheritance. Just make two separate classes.

You can usually tell when your inheritance ideas are bad if your primary reason is "code reuse".

baquerd
Jul 2, 2007

by FactsAreUseless
So I received the following window on my screen:



This is related to the commercial game "Left 4 Dead".

Is it best practices to leave assert statements in C++ code? This seems like a dev written debugger too?

Also, any idea why it would be referencing a "U" drive that is invisible to windows explorer both before, during, and after running the game?

Scaevolus
Apr 16, 2007

quadreb posted:

So I received the following window on my screen:



This is related to the commercial game "Left 4 Dead".

Is it best practices to leave assert statements in C++ code? This seems like a dev written debugger too?
Well, it would make sense to leave in an assertion that new allocations worked.

quote:

Also, any idea why it would be referencing a "U" drive that is invisible to windows explorer both before, during, and after running the game?
U:\ is probably a network drive that their build machine pulled the source code from.

baquerd
Jul 2, 2007

by FactsAreUseless

Scaevolus posted:

Well, it would make sense to leave in an assertion that new allocations worked.

U:\ is probably a network drive that their build machine pulled the source code from.

Shouldn't they have rolled over into a more user friendly "This application has crashed due to <blank>" instead of giving a debugger option that causes a crash likely because it expressly uses an in-house one for them?

And I'm not really seeing this network drive idea of yours. I might see the statement be something like (treat as pseudocode):

code:
   displayDebugger(String relPathToAssertFailure) {
     ...
     print "U:" + relPathToAssertFailure;
   }
But that seems awkward and stupid. If the drive doesn't exist on my computer, why would it be linked like that?

Vanadium
Jan 8, 2005

quadreb posted:

If the drive doesn't exist on my computer, why would it be linked like that?

The compiler just stored the path to the source file with the debugging symbols. Why should it care whether you happen to have a drive with the same name?

baquerd
Jul 2, 2007

by FactsAreUseless

Vanadium posted:

The compiler just stored the path to the source file with the debugging symbols. Why should it care whether you happen to have a drive with the same name?

I can see that, I guess. Still seems a bit odd for them to leave that sort of code in a published version.

Vanadium
Jan 8, 2005

Maybe, but I have seen it happen with a bunch of commercial applications.

6174
Dec 4, 2004

floWenoL posted:

It's been a while since I've worked with Linux packaging, but I believe you won't get the symlinks unless you have the package <FOO>-dev (or similar) installed.

At least according to the Debian Policy Manual that is correct. Thanks for the clarification.

StumblyWumbly
Sep 12, 2007

Batmanticore!
Where can I find info about how Linker scripts work?

To give some background: I'm writing a program for a microprocessor, not much of an OS. I need the entire program stored in flash but run from RAM. I can do this easily for functions I've written, but the compiler adds in functions like memcpy and __divsf3 (handles floating point division), and I'd like all that run out of RAM as well.

Any thoughts?

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS
What kind of microprocessor?

Adbot
ADBOT LOVES YOU

StumblyWumbly
Sep 12, 2007

Batmanticore!

ante posted:

What kind of microprocessor?
It's actually a NIOS II processor, embedded in an FPGA

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