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
Lorem ipsum
Sep 25, 2007
IF I REPORT SOMETHING, BAN ME.
From the "known issues" section of the NEW! XC8 compiler from Microshit:

1) For PIC18 devices and when the compiler is operating in PRO mode, assignment of an address to a pointer that is a member of a union which in tern is part of a structure may fail if the member is accessed via structure pointer a in the following example.

Pointers are hard ok

2) If a function returns a pointer, the size of this pointer is larger than 1 byte, and also larger than the total size of all the parameters passed to this function, then the memory used by the return value may not be allocated. The function's return value may overwrite other local variables and lead to code failure. Consider adding a dummy parameter to the function with the same size as the return value type.

Thanks for the sane workaround!

3) Structures which are auto cannot be initialized.

I mean I guess I can see how they didn't catch this

4) If a constant is used as the index into an array of const int type, the element read may be incorrect.

I don't even understand how that bug comes into being.

5) Variables which are absolute and which are not const cannot be initialized. The following example will not generate an error, but will not work as expected. Define the variable as absolute and initialize it in main-line code.

unsigned int varname @ 0x0200=0x40; // will not work as expected


...and this is what led me to this list.

6) Arrays that qualified as eeprom and which are initialized may not have all initial values written to the EEPROM.

They really hate initializing poo poo. Never initialize anything. Ever.

Adbot
ADBOT LOVES YOU

evensevenone
May 12, 2001
Glass is a solid.
Writing C compilers for 8-bit processors has to be a colossal pain in the rear end.

KaneTW
Dec 2, 2011

No Microchip is just the worst vendor ever.

Lorem ipsum
Sep 25, 2007
IF I REPORT SOMETHING, BAN ME.
Letters from microchip support part 1:


Hello [Ipsum],

The MCU8 divisional applications engineer has sorted out the TO bit issue for you. They state that this relates to a project options setting in the Build Options/Linker/ fields. You will need to uncheck the Clear bss and Initialize data settings.

Regards,
P.K

b0lt
Apr 29, 2005
Objective-C code:
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
 
@interface aaagh : NSObject
- (void)
wtf;
@end
 
@implementation aaagh
- (void)
wtf {
    printf("wtf\n");
}
@end
 
class Test : private objc_object {
public:
    Test(void) {
        this->isa = [aaagh class];
    }
 
    operator id (void) const {
        return (id) this;
    }
};
 
int main(void) {
    Test foo;
    [foo wtf];
}
I am somewhat considering using this in production, help someone stop me the horror is coming from inside the house

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
Objective-C code:
                                                                                // Hi! I'm an ugly hack!
                                                                                // For some reason, NSXMLDocument makes goddamn *Tidy warnings
                                                                                // NSErrors without anything other than the word warning in their
                                                                                // localized description to tell you that this isn't a real parse
if ([err.localizedDescription rangeOfString:@"Warning"].location != NSNotFound) // error! More proof of my "Principle of Most Surprise" theory....
I'm honestly not sure what the worst part of this is, the problem or the solution.

Sinestro fucked around with this message at 11:18 on Jun 8, 2013

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



b0lt posted:

Objective-C code:
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
 
@interface aaagh : NSObject
- (void)
wtf;
@end
 
@implementation aaagh
- (void)
wtf {
    printf("wtf\n");
}
@end
 
class Test : private objc_object {
public:
    Test(void) {
        this->isa = [aaagh class];
    }
 
    operator id (void) const {
        return (id) this;
    }
};
 
int main(void) {
    Test foo;
    [foo wtf];
}
I am somewhat considering using this in production, help someone stop me the horror is coming from inside the house

How does that work, where does alloc/init get called? Is that implicit in Objective-C++? Or is it the fact that you're isa-swizzling that's obviating the need?

Also, what is the point, it just seems like adding more code for no reason.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
It's getting allocated on the stack, so there's no need to alloc memory on the heap for it. Calling init would be needed if one were ever to subclass from it with an obj-C class, but the constructor is doing everything that [NSObject init] needs to do.

Suspicious Dish
Sep 24, 2011

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

Sinestro posted:

I'm honestly not sure what the worst part of this is, the problem or the solution.

If you encountered the same problem, what would you do?

return0
Apr 11, 2007

b0lt posted:

Objective-C code:
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
 
@interface aaagh : NSObject
- (void)
wtf;
@end
 
@implementation aaagh
- (void)
wtf {
    printf("wtf\n");
}
@end
 
class Test : private objc_object {
public:
    Test(void) {
        this->isa = [aaagh class];
    }
 
    operator id (void) const {
        return (id) this;
    }
};
 
int main(void) {
    Test foo;
    [foo wtf];
}
I am somewhat considering using this in production, help someone stop me the horror is coming from inside the house


Can you (or someone who knows about ObjectiveC/C++ interop) explain the horror here as it looks reasonable to me but I am clueless about Objective C so...

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal

return0 posted:

Can you (or someone who knows about ObjectiveC/C++ interop) explain the horror here as it looks reasonable to me but I am clueless about Objective C so...

In objc everything is derived from objc_object, including class and interface definitions.

objc_object has a member 'isa' which points to its class definition object, and a method 'class' that returns its isa.

So he creates the interface aaagh, which you usually just specify when making a class, but then the class Test instead of implementing aaargh explicitly assigns its isa pointer to the class of the interface itself, which winds up valid since Test doesn't have any members. Net result is an interface instantiated as an object. I guess if you really needed pointers to interfaces for some reason it'd be useful, but otherwise it's just a weird abuse of the base objc inheritance.

E: Missed that he defined 'id' too. [object id] in objc is a basic object method equivalent to { return (void*) this; } and I'm pretty sure it's not in objc_object, just NSObject (the base instantiated object class). This is basically The Thing : objc edition.

bucketmouse fucked around with this message at 19:48 on Jun 8, 2013

pseudorandom name
May 6, 2007

bucketmouse posted:

which winds up valid since Test doesn't have any members.

virtual functions, not members.

Objective C objects are just structs with the first element being an isa pointer.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

b0lt posted:

I am somewhat considering using this in production, help someone stop me the horror is coming from inside the house

As pointed out by others, you want this:

Objective-C code:
    operator id (void) const {
        return (id)(objc_object *)this;
    }
And believe it or not, this is an actual OO (anti-)pattern called metamorphism. It was apparently used a lot by old-school Visual Basic (except what they set at runtime was a C++ vtable pointer), and it was one of the reasons Windows Office for x86 and MacOS Office for PowerPC had VBA, but MacOS Office for x86 didn't (the gist of it being: "I know this might be shocking to you given the high quality of VB, but we actually did a lot of horrible non-portable poo poo inside it")

bucketmouse posted:

E: Missed that he defined 'id' too. [object id] in objc is a basic object method equivalent to { return (void*) this; } and I'm pretty sure it's not in objc_object, just NSObject (the base instantiated object class). This is basically The Thing : objc edition.

It's actually a conversion operator to the built-in Objective C type "id", which is like void * for Objective C objects

hackbunny fucked around with this message at 20:30 on Jun 8, 2013

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Suspicious Dish posted:

If you encountered the same problem, what would you do?

:ssh: That != should be ==. As written, that code ignores all errors that aren't Tidy warnings.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I didn't know, because I didn't see what the inside of the if statement did.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Suspicious Dish posted:

I didn't know, because I didn't see what the inside of the if statement did.

No problem, I was just a little too agressive at chopping away.

Objective-C code:
NSError *err;
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data options:NSXMLDocumentTidyHTML | NSXMLDocumentTidyXML error:&err];
if (err != nil)
{
                                                                                 // Hi! I'm an ugly hack!
                                                                                 // For some reason, NSXMLDocument makes goddamn *Tidy warnings
                                                                                 // NSErrors without anything other than the word warning in their
                                                                                 // localized description to tell you that this isn't a real parse
 if ([err.localizedDescription rangeOfString:@"Warning"].location != NSNotFound) // error! More proof of my "Principle of Most Surprise" theory....
 {
     [[NSNotificationCenter defaultCenter]
      postNotificationName:@"FBError"
      object:err];
     
     return;
 }
}

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

b0lt posted:

I am somewhat considering using this in production, help someone stop me the horror is coming from inside the house

It's just a form of custom allocation. Stack- or bulk- allocating objects that you plan to hand off to system routines has some obvious risks — you need to be by careful that the objects don't escape, including by ending up in the autorelease pool — but it can also be a serious optimization if allocation costs are killing you.

Usually, though, a better answer is to figure out some way to make these objects not have to be Objective-C objects at all.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Sinestro posted:

No problem, I was just a little too agressive at chopping away.
the real horror is the placement of that comment

Salynne
Oct 25, 2007

Aleksei Vasiliev posted:

the real horror is the placement of that comment

I'm inclined to agree. That's not where that goes :colbert:

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

My job literally just called me posted:

:downs:"Hey 2banks what's up?"

:toot:Nothing, why?

:downsrim:"Hey that bug we have? To fix it, we need you to delete the original input file that you're preprocessing and copy over it from the output file you generated."

:toot:Okay.

I don't even know what to say.

I am not trolling. I am serious. I was just told to do this.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

2banks1swap.avi posted:

I don't even know what to say.

I am not trolling. I am serious. I was just told to do this.

I don't understand. They told you to take the output of a process, and replace the input to that process with the output?

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
Yeap. I don't either.

Why the temp file can't be used (why bother making it just to copy the contents of it over the original file???) is lost to me.

Is this normal and I'm just being an idiot ?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I love corporate open-source dumps.

code:
//
// SONY CONFIDENTIAL
//
void main(
    float4     color_in  : COLOR,
    float4 out color_out : COLOR)
{
    color_out = color_in;
}

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I may not be understanding what you're saying, but programs that are supposed to modify a file often work by writing to a temporary file and then renaming that temporary to the original rather than just overwriting the original file directly. This updates the file atomically; otherwise, processes which are racing with the modifying program can see an incompletely-written file.

Really, the only reason not to do this is if the file is so big that making two copies is a performance issue, or if you're totally certain for some reason that nobody will access that file while you're writing to it.

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
I must be extremely risk-averse; I'd think you should keep the original file and just use the temp file, in case something went wrong.

I stand corrected.

Innocent Bystander
May 8, 2007
Born in the LOLbarn.
The usual PHP horror:

code:
<?php

function what_do_i_return($i) {
    switch($i) {
        case 'k':
            return 'k';
        case 0:
            return '0';
        default:
            return 'default';
    }
}

print what_do_i_return(0);

?>
This prints

code:
k
Thank you loose typing and insane conversion directives.

I understand why it returns what it does, but its still completely stupid.

Innocent Bystander fucked around with this message at 04:35 on Jun 11, 2013

evensevenone
May 12, 2001
Glass is a solid.
edit no it isn't.

evensevenone fucked around with this message at 04:39 on Jun 11, 2013

RoadCrewWorker
Nov 19, 2007

camels aren't so great
Haven't worked with PHP in years, is the horror that the first comparison dynamically casts 0 to '0' which persists and then fails the second comparison so the return value is 'default'?

More importantly, is my ignorance bliss (in this case)?

Innocent Bystander
May 8, 2007
Born in the LOLbarn.
It absolutely is bliss!

Whenever you try to compare a string to a number in PHP, PHP tries to convert the string to a number, and if the string cannot be cast to a number, or does not start with a number, it will assume you want 0 as its numerical value, and compare it that way.

So in the switch statement, it attempts to compare 'k' to 0, so the 'k' gets cast to a number, which will be 0, so that case is fulfilled and the above example prints 'k'.

ephphatha
Dec 18, 2009




Oh PHP. http://codepad.org/Ts3BDpjM

PHP code:
<?php

function what_do_i_return($i) {
    switch($i) {
        case 'k':
            return 'k';
        case 0:
            return '0';
        default:
            return 'default';
    }
}

print what_do_i_return(0)."\n";
print what_do_i_return('f')."\n";
print what_do_i_return(9)."\n";

?>


Output:
k
0
default
Edit: I was interested in what would happen with other cases for the code above in case it wasn't obvious. I don't use PHP so I guessed this would be the output but figured it prudent to test.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

2banks1swap.avi posted:

I must be extremely risk-averse; I'd think you should keep the original file and just use the temp file, in case something went wrong.

I stand corrected.

The rename-the-temporary pattern avoids risk much more effectively than modifying the file in-place.

Let's spell this out. The pattern here is:

  • Open the original file for reading only. If somebody tries to write to it concurrently, you might see an inconsistent state, but that's true under in-place rules, too.
  • Open a temporary file for writing. In theory, since this is an anonymous temporary file, you do not need to worry about anybody else reading or writing to it. Certainly you do not need to worry about people looking for the original file seeing your half-written file, because hey, you haven't touched that file!
  • Finish your operation and close your files.
  • You now have an internally-consistent original file and an internally-consistent new file. If anything terrible happens to your process before this point, the worst case is that you leave a temporary file scattered around (and even this is quite easy to protect against in simple cases like a crashing process).
  • Now you do the rename, which is just a matter of the OS atomically updating some metadata. Any process opening the file will see one set of consistent contents or the other.

Note that the standard pattern is to just do a rename, not a delete and rename. The latter is unnecessary (on POSIX systems) and introduces the possibility that a racing process could see a "partial write" (specifically, they could try to open the file and have it fail).

If you need to protect against concurrent readers, this is just how you have to do it.

On the other hand, not replacing the file has the merit that all the metadata associated with the original file is automatically preserved.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
Oh gently caress PHP, gently caress it hard. Is there a saner language that compiles to PHP, like CoffeScript compiles to Javascript? This poo poo is un-loving-believable

b0lt
Apr 29, 2005

hackbunny posted:

Oh gently caress PHP, gently caress it hard. Is there a saner language that compiles to PHP, like CoffeScript compiles to Javascript? This poo poo is un-loving-believable

Why the gently caress would you want something that compiles to PHP? :psyduck:
Dart et al. only exist because javascript is the only thing that you can use on a browser.

Deus Rex
Mar 5, 2005

hackbunny posted:

Oh gently caress PHP, gently caress it hard. Is there a saner language that compiles to PHP, like CoffeScript compiles to Javascript? This poo poo is un-loving-believable

there are some strange, unfinished languages which purport to do this but i'd suggest you stay away from them.

which version of PHP are you using? the pain you shall endure is inversely proportional to the version number though it will be great regardless

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

hackbunny posted:

Oh gently caress PHP, gently caress it hard. Is there a saner language that compiles to PHP, like CoffeScript compiles to Javascript? This poo poo is un-loving-believable

XHP.

Or learn not to do anything that might do implicit casting without thinking it over, stockholm syndrome style. PHP is a really good platform, though.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Old-rear end PHP (like, code compatible with php4 or something) is an amazing platform, because it will run on even the most cheap and lovely of shared hosts.

Modern php is far worse because the language is still terrible (just less so), and anywhere that will let you run it will also usually let you run something far better.

Zombywuf
Mar 29, 2008

hackbunny posted:

Oh gently caress PHP, gently caress it hard. Is there a saner language that compiles to PHP, like CoffeScript compiles to Javascript? This poo poo is un-loving-believable

http://www.joelonsoftware.com/articles/FogBugzIII.html

xf86enodev
Mar 27, 2010

dis catte!

The fact that Joel Onsoftware actually makes money with his poo poo and is even regarded as some kind of software icon amazes me to no end.

Jewel
May 2, 2009


quote:

In Apps Hungarian you still have the prefixes, but they are supposed to add semantic information, not merely repeat the type of a variable. So for example when you have a buffer size, the variable should be named "cb", which means "count of bytes". Whenever you're writing C++ code that needs to deal with all kinds of strings, it's really nice to be able to look at the variable name, and if it's a psz, you know, oh, look, it's a pointer to a null-terminated string, but no memory is allocated! Or if it starts with rgch, you know it's an array of characters, with memory allocated, or rgwch, you know it's an array of Unicode (wide) chars, or if it starts with ix you know it's an index to something (or a primary key in SQL), etc. etc.

:frogsiren: :gonk: :frogsiren:

This is loving terrible? Why yes remembering that if something starts with rgwch means an array of unicode wide characters IS something that's in my mind on a day to day basis, thanks!

Adbot
ADBOT LOVES YOU

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

I want to punch this page in the ear and you too for suggesting it. We get it Joel, you're an IT entrepreneur who was the youngest PM at Microsoft and held his own against Bill loving Gates, jesus christ stop fellating yourself for two seconds. And I used to admire the guy and follow his blog religiously :cripes: I even remember this particular entry and used to remember it fondly :cripes: Thanks for making me realize what kind of idiot I was, I guess?

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