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
New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Manslaughter posted:

I've been given an assignment to create an XSL that will insert the appropriate RTF tags to format XML to a client's liking.

You heard right, RTF. I'm going to manually insert these tags all over an XSL file so that XML goes in one end and a pretty doc (with an RTF extension) comes out the other.

Will post trip report if my brain does not melt out one of my ears before I'm done.

bonus round: One of the items on the client list is a watermark

Did you have a discussion with the source of the request to see why they want/need that? 90% of the time when a totally nonsensical request comes through, it's because no one understands what they actually want or need.

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Plorkyeran posted:

Might as well save some time and annoyance and just kill yourself now.

The note better be well-formed or the attempt will probably just error out.

Polio Vax Scene
Apr 5, 2009



Ithaqua posted:

Did you have a discussion with the source of the request to see why they want/need that? 90% of the time when a totally nonsensical request comes through, it's because no one understands what they actually want or need.

Client needs: Docs that are formatted to their preferences
Our needs: Money, and a new system that supports something other than RTF (yeah right)

TBH this client has no idea what they want. They'll request customization, get billed for it, then request that exact same customization be removed (and you better believe they get billed the same amount for removal).

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Manslaughter posted:

I've been given an assignment to create an XSL that will insert the appropriate RTF tags to format XML to a client's liking.

You heard right, RTF. I'm going to manually insert these tags all over an XSL file so that XML goes in one end and a pretty doc (with an RTF extension) comes out the other.

Will post trip report if my brain does not melt out one of my ears before I'm done.

bonus round: One of the items on the client list is a watermark

At first I read that as "XLS", and thought they wanted Excel macros. So, look on the bright side...

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Suspicious Dish posted:

At first I read that as "XLS", and thought they wanted Excel macros. So, look on the bright side...

I'm not sure that'd be worse. If you have access to Word's stuff from excel macros then it'd actually be easier to create a RTF file from there than via XSLT.

shrughes
Oct 11, 2008

(call/cc call/cc)

Steve French posted:

If you're going to build a shed with pointers,
C code:
int isPalindrome(char *s, size_t len) {
  char *e = s + len - 1;
  while (s < e) if (*s++ != *e--) return 0;
  return 1;
}

That is indeed an appropriate contribution for this thread, since it has undefined behavior on one of its inputs.

Harik
Sep 9, 2001

From the hard streets of Moscow
First dog to touch the stars


Plaster Town Cop

Jewel posted:

I was confused about why "warning = limit * persentage" wouldn't work. I haven't worked with C++ in a little while so I thought "hm, does 'limit * persentage' create a new unsigned char of the multiplication, then cast that to long? I thought that makes sense so I did a quick test to see what the output would be. I got:

C++ code:
#include <iostream>

void multiply(unsigned char a, unsigned char b)
{
    unsigned long result;
    result = a * b;

    std::cout << +a << " * " << +b << " = " << result << std::endl;
}

int main()
{
    multiply(5, 5);
    multiply(255, 255);

    return 0;
}
With the output of:

code:
5 * 5 = 25
255 * 255 = 65025
Why is this? It seems to work? So my two questions: Why did their code snippet not work, and why does this work with regards to casting and overflow?
It's on an 8-bit processor, where anything other than 8bit * 8bit multiply requires a function call. Even if C didn't specify promotion, your compiler would have to go out of it's way to poo poo on you since you're building on a machine with at least 32-bit registers if not 64, so it'd have to multiply & mask. As far as the original horror, on the hardware it should be u8*u8=u16 (two register destination). So probably "broken compiler", it wouldn't be the first time. Casting or assigning either operand to a long fixed it though:

C++ code:
void multiply(unsigned char a, unsigned char b) {
    unsigned long result=a;

    result = result * b;
}
The uninitialized variable in the example was me, I'm the cut&paste horror when distilling a monster 200 line function down to the fuckup.

I keep "persentage" around to remind me how much I hate cleaning up other people's messes. It's a great source of rage when I have to poke around the spaghetti pile for whatever minor misfeature I need to add.

Except I don't anymore, since it's all rebuilt on a new chip so oh well that PIC-specific code just gosh darn didn't port and I had to re-implement.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Scaevolus posted:

Fizzshedding: dozens of replies arguing about implementations of a trivial interview question.

This happens every time someone posts about interview questions. Some of you nerds just can't help making it into an e-penis contest instead of focusing on, you know, the actual discussion. Hey everyone, look at meeeeeeeeee!

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
Many programmers lack the self-awareness necessary to understand when writing code is not the solution, and the code they write winds up in this thread.

:ironicat:

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Smugdog Millionaire posted:

Many programmers lack the self-awareness necessary to understand when writing code is not the solution, and the code they write winds up in this thread.

:ironicat:

Really, we're just being efficient.

shrughes
Oct 11, 2008

(call/cc call/cc)

Ender.uNF posted:

This happens every time someone posts about interview questions. Some of you nerds just can't help making it into an e-penis contest instead of focusing on, you know, the actual discussion. Hey everyone, look at meeeeeeeeee!

:nyd: The discussion is whatever we make the discussion.

Steve French
Sep 8, 2003

Ender.uNF posted:

This happens every time someone posts about interview questions. Some of you nerds just can't help making it into an e-penis contest instead of focusing on, you know, the actual discussion. Hey everyone, look at meeeeeeeeee!

Wait, so are you participating in the actual discussion?? Here I thought it was reasonable to talk about code.

I helped start the "derail" by asking some pointed questions intended to highlight the possibility that someone had misunderstood why their interview performance was perceived as poor.

THEN I put forth my entry in the e-penis contest because guess what? I actually enjoy thinking of and implementing various solutions to these sorts of problems.

AND I ended up learning something from it. From shrughes, who you all seem to hate for some reason or another. Maybe be less upset about things I guess?

return0
Apr 11, 2007

shrughes posted:

That is indeed an appropriate contribution for this thread, since it has undefined behavior on one of its inputs.

Out of curiosity what's the UB?

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

return0 posted:

Out of curiosity what's the UB?

I've written all of ~ten lines of C in my life, but undefined behaviour is usually at the boundaries. In this case, set len = 0. Then e = s - 1, and (if I'm remembering rightly) since pointers to arrays are pointers to their first element, e is a pointer to one before the first element, which is an invalid pointer.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Obviously it just requires that you start your strings at the second byte of the allocation.

Admiral H. Curtiss
May 11, 2010

I think there are a bunch of people who can create trailing images. I know some who could do this as if they were just going out for a stroll.
Isn't that a moot point anyway? At len=0, the while loop ends up as (s < s-1), which immediately fails and the function returns 1. You're never dereferencing the pointer that way.

qntm
Jun 17, 2009
code:
if (capturedXML.startsWith("HEX")) {
    ...
}
:raise:

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Admiral H. Curtiss posted:

Isn't that a moot point anyway? At len=0, the while loop ends up as (s < s-1), which immediately fails and the function returns 1. You're never dereferencing the pointer that way.
I was a bit surprised, but I checked the C99 draft and it says that only address calculations within an array and just past the end are defined. An address just before the beginning is right out, regardless of whether you dereference it.

qntm
Jun 17, 2009

Gazpacho posted:

I was a bit surprised, but I checked the C99 draft and it says that only address calculations within an array and just past the end are defined. An address just before the beginning is right out, regardless of whether you dereference it.

There aren't any arrays in that code...?

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
Generally speaking, if the pointer isn't pointing into an array then you've done something undefined before you call the function.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

qntm posted:

There aren't any arrays in that code...?
She's passing a pointer and a length. That's an idiom for passing an array, and in this case it's an array of chars, which is one way to represent a string.

coffeetable fucked around with this message at 20:07 on Feb 4, 2014

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
The reason I thought "Oh, a higher level language - I'll split and flip one half then compare!" was because I had just come from C.

Welp.

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

qntm posted:

There aren't any arrays in that code...?
For arithmetic operations, pointers to objects that are not part of an array shall behave the same as pointers to the first element of a one-element array of the same object type. As soon as your calculation produces a pointer that lies outside of that (real or fictional) array, even as a temporary value, the behavior is undefined - unless the pointer points one past the last element, which is allowed as a special exception.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
edit: wrong thread

Fuck them fucked around with this message at 22:33 on Feb 4, 2014

shrughes
Oct 11, 2008

(call/cc call/cc)

Admiral H. Curtiss posted:

Isn't that a moot point anyway? At len=0, the while loop ends up as (s < s-1), which immediately fails and the function returns 1. You're never dereferencing the pointer that way.

On a somewhat plausible architecture, s could underflow resulting in an incorrect result from the comparison. On other architectures, if the compiler inlined the function, the compiler could hypothetically assume that len > 0 based on the code it sees (because undefined behavior) and generate assembly code that doesn't do the right comparison the first time it enters the loop.

Tesseraction
Apr 5, 2009

That actually sounds pretty interesting - which compilers do that? I'm self-studying optimisation at the moment so that'd be a good thing to look at.

shrughes
Oct 11, 2008

(call/cc call/cc)
I'm not naming a specific optimization that a compiler might do or any compiler behavior I specifically know about. This is just a hypothetical code generation decision (which seems pretty unlikely).

You could imagine it generating some assembly that for whatever reason looks something like this:

code:

    e = s + len - 1
    cmp s, e
    jz bottom_of_loop
top_of_loop:
    ...

    incr s
    decr e
    cmp s, e
    jl top_of_loop
end_of_loop:
where it decides without any particular optimization in mind that it would like to use a jump-if-zero instruction instead of jump-if-not-less-than because it "knows" len is not 0. And where it has comparisons at both ends of the loop (which happens sometimes).

You can see other circumstances where undefined behavior results in a surprise optimization, like seen http://lwn.net/Articles/342330/ <- there.

return0
Apr 11, 2007

shrughes posted:

You can see other circumstances where undefined behavior results in a surprise optimization, like seen http://lwn.net/Articles/342330/ <- there.

This is pretty cool tbh

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Steve French posted:

Wait, so are you participating in the actual discussion?? Here I thought it was reasonable to talk about code.

I helped start the "derail" by asking some pointed questions intended to highlight the possibility that someone had misunderstood why their interview performance was perceived as poor.

THEN I put forth my entry in the e-penis contest because guess what? I actually enjoy thinking of and implementing various solutions to these sorts of problems.

AND I ended up learning something from it. From shrughes, who you all seem to hate for some reason or another. Maybe be less upset about things I guess?

:thejoke:

Tesseraction
Apr 5, 2009

shrughes posted:

where it decides without any particular optimization in mind that it would like to use a jump-if-zero instruction instead of jump-if-not-less-than because it "knows" len is not 0. And where it has comparisons at both ends of the loop (which happens sometimes).

You can see other circumstances where undefined behavior results in a surprise optimization, like seen http://lwn.net/Articles/342330/ <- there.

Interesting - thanks for the clarification. It's a good example of a compiler not following its supposed principles (i.e. not changing semantics) due to ambiguous syntax. Good eye!

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

Steve French posted:

AND I ended up learning something from it. From shrughes, who you all seem to hate for some reason or another.
It's possible for someone to be both very knowledgeable and a bit of an rear end in a top hat.

Tesseraction
Apr 5, 2009

Yeah I mean I disagree with shrughes on most social points but he knows his C (family).

FamDav
Mar 29, 2008

2banks1swap.avi posted:

The reason I thought "Oh, a higher level language - I'll split and flip one half then compare!" was because I had just come from C.

Welp.

Why?

shrughes
Oct 11, 2008

(call/cc call/cc)

Tesseraction posted:

Yeah I mean I disagree with shrughes on most social points

I doubt this is true. I only argue with irrational arguments people here make because they're irrational, not because the end conclusion is right or wrong.

Tesseraction
Apr 5, 2009

shrughes posted:

I doubt this is true. I only argue with irrational arguments people here make because they're irrational, not because the end conclusion is right or wrong.

I will willingly and happily argue this, hoping to be wrong, but not in this thread.

Deus Rex
Mar 5, 2005


raminasi
Jan 25, 2005

a last drink with no ice

Tesseraction posted:

Interesting - thanks for the clarification. It's a good example of a compiler not following its supposed principles (i.e. not changing semantics) due to ambiguous syntax. Good eye!

I think you still might not fully understand what undefined behavior is all about.

Tesseraction
Apr 5, 2009

No, I'm pretty sure I do. Sorry my post produced undefined behaviour in your interpretation?

shrughes
Oct 11, 2008

(call/cc call/cc)

Tesseraction posted:

No, I'm pretty sure I do. Sorry my post produced undefined behaviour in your interpretation?

You said the compiler changed semantics when in fact it didn't.

Adbot
ADBOT LOVES YOU

Sedro
Dec 31, 2008
It would work half the time

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