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
prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band
this is probably old news, but i like being able to say "i told you so" because i think omitting braces from one-line if statements is bad and wrong and sinful

code:
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams,
                                 uint8_t *signature, UInt16 signatureLen)
{
	OSStatus        err;
	...

	if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
		goto fail;
	if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
		goto fail;
		goto fail;
	if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
		goto fail;
	...

fail:
	SSLFreeBuffer(&signedHashes);
	SSLFreeBuffer(&hashCtx);
	return err;
}
this is the apple security bug that required updates a couple of weeks ago: https://www.imperialviolet.org/2014/02/22/applebug.html

Adbot
ADBOT LOVES YOU

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

hackbunny posted:

C++ is almost a perfect superset of C, except for non-overlapping keyword sets, some C99 features and a handful of pitfalls, small and big. some of the weirdest ABI issues in C++ (like the format of pointers to member functions) stem almost entirely from the unwritten rule that all C++ code must be able to compile to a C "assembly" form. there is no "magic" to C++ and that's why sometimes I joke that if it can be done in C++ then it's "real code" (meaning it runs on the classical Von Neumann architecture)

the absence of "magic" to C++ (and C) is the major reason you can't compile C++ (or C) for the JVM (by design not a Von Neumann architecture)

what

c isn't tied to von neumann architecture i mean it compiles on harvard architecture microprocessors

u can totes compile C for the jvm, just store everything on a stack. the jvm is a stack machine for its bytecode but that doesn't mean it can't work with register based architectures

there's a lot of magic in C++ i mean the rules for how syntax desugars is incomprehensible to normal humans + templates. also vtables will trip everyone up before they realize that yes, C++ style objects have a cost

C has less magic but vast chunks of it are left unspecified

Workaday Wizard
Oct 23, 2009

by Pragmatica

hackbunny posted:

JVM (by design not a Von Neumann architecture)

hello i am babby please explain what does it mean for jvm to be not von neumann arch

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

Shinku ABOOKEN posted:

hello i am babby please explain what does it mean for jvm to be not von neumann arch

von neumann architectures use the same storage for instructions and data

harvard architectures use different storage for instructions and data

most modern systems use a modified harvard architecture, where instructions and data are both backed by the same storage, but they're cached separately

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Shinku ABOOKEN posted:

hello i am babby please explain what does it mean for jvm to be not von neumann arch

von neumann is shared data/code memory basically

harvard is separate data and code memory

JVM is a von neumann stack machine

some microcontrollers have a harvard architecture where u have separate code/data memory

of course modern cpu's blur the distinction and caches can be split (icache v dcache) and there's segmentation/protection like no execute bits

it's not really relevant to high level programming but if you're doing embedded/ low level stuff correctly placing data and code is v important

prefect
Sep 11, 2001

No one, Woodhouse.
No one.




Dead Man’s Band
if the jvm is von neumann and the cpu is harvard, does that mean the jvm ultimately translates its stuff from one style to the other, in order to communicate with the hardware?

Nomnom Cookie
Aug 30, 2009



from what i recall the jvm spec doesn't address or expose code storage. bytecode would go in data ram, jitted methods in code ram. i don't think you can reasonably pin down the jvm as von neumann or harvard

Cybernetic Vermin
Apr 18, 2005

not being able to programmatically access the code is pretty clear harvard architecture though

everything is very hybrid though (you can after all programmtically manipulate bytecode anyway, but need to use specific api entrypoints, i.e. classloaders, to do so)

i don't think the distinction is terribly useful today

tef
May 30, 2004

-> some l-system crap ->

Mr Dog posted:

yeah just give me unsigned types in Java and all that remains is at best minor nuisances.

http://javolution.org/target/site/apidocs/javolution/io/class-use/Struct.Member.html :toot:

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

quote:

class Struct.Signed16
This class represents a 16 bits signed integer.
class Struct.Signed32
This class represents a 32 bits signed integer.
class Struct.Signed64
This class represents a 64 bits signed integer.
class Struct.Signed8
This class represents a 8 bits signed integer.
class Struct.Unsigned16
This class represents a 16 bits unsigned integer.
class Struct.Unsigned32
This class represents a 32 bits unsigned integer.
class Struct.Unsigned8
This class represents a 8 bits unsigned integer.
class Struct.UTF8String
This class represents a UTF-8 character string, null terminated (for C/C++ compatibility)

it's nice that they still managed to sneak a splinter in the programmer's foot after taking the railroad spike out of his kneecap. demonstrates that they're thoughtful misanthropes

Notorious b.s.d.
Jan 25, 2003

by Reene

FamDav posted:

i would love a solid base layer common IDE component that handled code parsing, syntax highlighting, compiler/debugger integration, vcs, maybe some code sharing networking etc. and then on top of that spergs could build their intellij's, emacs, and vim. it would be cool because you could have your vim exactly as it in the terminal or your emacs or whatever but everybody is actually on the same platform.

this exists, i discussed it earlier, it is called eclipse

you can use the eclipse swt ui
you can use vim
you can use emacs

in all cases you get the same compiler/debugger integration, code analysis, etc

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

Malcolm XML posted:

what

c isn't tied to von neumann architecture i mean it compiles on harvard architecture microprocessors

ok ok my bad, I shouldn't have mixed practical considerations with theoretic concepts. I don't even know that much theory in the first place

but

be serious. C is built on some assumptions. there are a lot of architectures, from the obscure (Symbolics Lisp Machine) to the mainstream (.NET CLI) and anything inbetween (Cray-2, Itanium) that violate a number of assumptions (Lisp Machine's pointers are object-offset tuples; CLI has variable-sized pointers; Cray-2 requires explicit allocation and deallocation of stack frames; Itanium has double indirection for function pointers; etc.), and there has been a huge combined effort in the last decade to reverse-engineer an abstract C machine that resulted in some crazy poo poo, but... it has to feel like C. emscripten is a cool porting tool but I bet it wouldn't really feel like C. this won't feel like C either:

Malcolm XML posted:

u can totes compile C for the jvm, just store everything on a stack. the jvm is a stack machine for its bytecode but that doesn't mean it can't work with register based architectures

haha oh wow, I suppose it's a step above that guy who made a "C-to-JVM compiler" by coupling a C compiler targetting MIPS with a MIPS simulator for JVM

Malcolm XML posted:

also vtables will trip everyone up before they realize that yes, C++ style objects have a cost

unless you've done vtables in C before. in that case, C++ vtables make total sense and you'd feel hurt if they were implemented in any other way. same goes for multiple virtual inheritance: you can do it in C with a creative use of offsetof (basically: you write the this-adjusting thunks by hand. this deserves a post on its own some time), and I can guarantee the design of the same feature in C++ was influenced by some vocal UNIX beardo's artisanal bespoke C macro set

I'll be the rear end in a top hat and suggest that you should go C -> ASM -> C -> C++ if you want to make sense of C++. and then start disassembling your C++ code (how else would you discover how ~horribly inefficient~ downcasting can be?)

Malcolm XML posted:

von neumann is shared data/code memory basically

harvard is separate data and code memory

JVM is a von neumann stack machine

ok, my only direct experience with JVM is Tanenbaum's toy MIC architecture for a Computer Architecture course, but by the time I was taking the course I already had a few years of experience with x86 assembler, and I immediately noticed a thing about JVM: it has a segmented memory model. you have a constants segment, a stack segment, a code segment, etc. plus the segment is implicit in each instruction and unlike x86 there aren't segment overrides so you can't read-write data from the code segment or execute code from the constants segment. it's not a "you'll get a fault/stale data"-cannot, it's the "there is no instruction for it"-cannot. JVM memory isn't really "addressable" in the way C assumes and I can't call it a Von Neumann architecture in good conscience

the fact that it's a stack vs register architecture is completely irrelevant and I don't know why you bring it up :shrug: there are far more bizarre architectures in that respect (see: Itanium) that still are 99.999% Von Neumann

Nomnom Cookie
Aug 30, 2009



Cybernetic Vermin posted:

not being able to programmatically access the code is pretty clear harvard architecture though

everything is very hybrid though (you can after all programmtically manipulate bytecode anyway, but need to use specific api entrypoints, i.e. classloaders, to do so)

i don't think the distinction is terribly useful today

i don't think the distinction was ever useful

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
the distinction is useful for creating acm award lectures to propagandize functional programming which will be quoted without understanding into eternity

Scaevolus
Apr 16, 2007

Another problem with C/C++ on safe/garbage collected runtimes is pointers and casting -- C is perfectly happy to let you make arbitrary pointers (including internal), peek at raw bytes, and reinterpret one type as another, which is awkward on the JVM.

Emscripten/asm.js emulates this by passing around a giant Uint8Array and using it to store concrete representations, but it's awkward.

C++/CLI has includes syntax for new pointer types that interact properly with the garbage collector.

Kevin Mitnick P.E. posted:

i don't think the distinction was ever useful
Memory used to be horribly expensive and slow and the idea of separate code/data memory banks to alleviate the bottleneck of a single bus was radical.

You can also do stupid poo poo like hard-realtime DSPs with no caches, guaranteed execution times, and good performance by throwing multiple data buses on it.

Scaevolus fucked around with this message at 17:38 on Mar 14, 2014

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance

hackbunny posted:

be serious. C is built on some assumptions. there are a lot of architectures, from the obscure (Symbolics Lisp Machine) to the mainstream (.NET CLI) and anything inbetween (Cray-2, Itanium) that violate a number of assumptions (Lisp Machine's pointers are object-offset tuples; CLI has variable-sized pointers; Cray-2 requires explicit allocation and deallocation of stack frames; Itanium has double indirection for function pointers; etc.), and there has been a huge combined effort in the last decade to reverse-engineer an abstract C machine that resulted in some crazy poo poo, but... it has to feel like C. emscripten is a cool porting tool but I bet it wouldn't really feel like C. this won't feel like C either:

i don't understand what you're trying to say here. the C standard does in fact describe an abstract machine. the job of the compiler is to translate source code into executable code for the target architecture that exhibits the semantics required by the standard. how that translation occurs is of course deliberately unspecified and it can be as simple or complex as is required. we're used to thinking of C as "close to the metal" but that's a historical conceit and not a requirement. things like llvm and emscripten demonstrate that this is true, not to mention the existence of a C compiler for just about any real-world architecture you could name. i don't have any idea what you mean when you say "feels like C." C is a relatively small language and you may be conflating it with some specific implantation, or personal assumptions that aren't actually present in standard C.

going back to your original point, there is no rule that C++ be compilable to any form of C and i would be shocked to find out that any modern compiler works that way. in fact the two languages diverged sometime prior to the first C standard and while the superficial similarities are many, the basic differences are both numerous and subtle, and it is neither helpful nor correct to conceive of either C being a subset of C++, or of C++ being a superset of C.

Bloody
Mar 3, 2013

but i can include both stdio and iostream in one file and cout and printf at the same time therefore c++ is a superset of c gg

also such a program will compile with both gcc and g++

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Bloody posted:

but i can include both stdio and iostream in one file and cout and printf at the same time therefore c++ is a superset of c gg

also such a program will compile with both gcc and g++

c/c++

Bloody
Mar 3, 2013

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

hackbunny posted:

I like it. I picked it up fast and things like interleaving parameters with segments of a method name look weird at first but you get used to it quickly. the guys previously assigned to my project were just big crybabies complaining about made up non-issues and I can do more work than the two of them combined

memory management was a bit of a culture shock at first, coming from COM, but once you get used to it it's very refreshing. autorelease pools are a brilliant idea and they let you free to use objects for lightweight data (see NSNumber, NSData, etc.). the message loop is a little complicated and I don't fully get it, but on the other hand I "get" the much messier Win32 message loop so it's probably just a matter of getting used

Objective C results in really clean code with few pitfalls, very newbie-friendly, that compiles very fast. totally beats the C++ or pseudo-C++ equivalents (our product originally ran on Symbian and you really really really don't want to know). the framework lacks many obvious things but adding extension methods to classes is really easy. the date/time functions are worse than average, but serviceable

UIkit is another matter entirely. I hate UIkit, it's a buggy piece of poo poo that lacks the most basic diagnostic tools

yeah my complaints about core framework are fairly small. the holes in functionality are just bizarre to me (because apple has obviously had to solve these problems so why not package it up?) but they're plugged easily enough. the language itself is pretty cool and i have to give it to apple, arc makes it feel like i'm working in a managed language. i have to be a little more careful about ownership but that's easily done.

incidentally i got my start in the industry in smalltalk so the "weird" message syntax that everyone cites is a return to roots for me :)

uikit is a huge pain though. it's amazing how often you have to write all the code from scratch to implement a "standard" idiom in ios. it's not a framework; it's a bundle of use cases that apple has happened to find useful.

Dr Monkeysee fucked around with this message at 18:00 on Mar 14, 2014

Cybernetic Vermin
Apr 18, 2005

HORATIO HORNBLOWER posted:

i don't understand what you're trying to say here. the C standard does in fact describe an abstract machine. the job of the compiler is to translate source code into executable code for the target architecture that exhibits the semantics required by the standard. how that translation occurs is of course deliberately unspecified and it can be as simple or complex as is required. we're used to thinking of C as "close to the metal" but that's a historical conceit and not a requirement

so this is simultaneously true and misleading, as "unspecified behavior" in c better loving mean exactly what it means in ye olde 80s c compiler

it is not nearly as difficult as it gets made out to be to just provide the flat memory space and the standard type representations, but the abstract idea of c from the specification is not really sufficient for anything real

i don't think it is that bad a thing that this is the situation though, i think the authors of the c specification imagined a future where minicomputers would continue to diverge, but as it happens flat memory spaces and standardized number representations made a lot of the specification unnecessarily abstract (in that the abstractions have long since given way to a standard set of assumptions)

pseudorandom name
May 6, 2007

Cybernetic Vermin posted:

so this is simultaneously true and misleading, as "unspecified behavior" in c better loving mean exactly what it means in ye olde 80s c compiler

except it doesn't

Notorious b.s.d.
Jan 25, 2003

by Reene

hackbunny posted:

unless you've done vtables in C before. in that case, C++ vtables make total sense and you'd feel hurt if they were implemented in any other way. same goes for multiple virtual inheritance: you can do it in C with a creative use of offsetof (basically: you write the this-adjusting thunks by hand. this deserves a post on its own some time), and I can guarantee the design of the same feature in C++ was influenced by some vocal UNIX beardo's artisanal bespoke C macro set

the beardo in question is Stroustrop. the artisanal bespoke C macro set is CFront.

you just described where c++ came from

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
while cfront did emit C, it wasn't actually a set of macros or a translator in its guts

Notorious b.s.d.
Jan 25, 2003

by Reene

Otto Skorzeny posted:

while cfront did emit C, it wasn't actually a set of macros or a translator in its guts

no, it's not a set of macros.

yes, it is a pretty "dumb" translator.

http://www.softwarepreservation.org/projects/c_plus_plus/cfront/release_e/src/cfront.pdf

it's hideous but readable. like if someone tried to bodge together a C++ to C translator in perl, then ported it to 1980s C++





the worst/scariest part:

wikipedia says it wasn't finally abandoned until 1993, because they couldn't get exception-handling to work properly.

I know that things went even further than that, because HP continued to use/sell CFront well into the 1990s

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

HORATIO HORNBLOWER posted:

i don't have any idea what you mean when you say "feels like C."

imagine running C code on an architecture where you can't address memory but on the other hand you have several features that would usually sit several layers on top of C. imagine in other words to run C on top of abstractions instead of primitives (don't get rule-lawyery on me):

Scaevolus posted:

Emscripten/asm.js emulates this by passing around a giant Uint8Array and using it to store concrete representations, but it's awkward.

tell me with a straight face that running C code on that platform (because by hook or crook you will get it to compile) is a good idea or useful

HORATIO HORNBLOWER posted:

going back to your original point, there is no rule that C++ be compilable to any form of C and i would be shocked to find out that any modern compiler works that way

I never thought "you can write C in C++" was even remotely controversial because of course you can, it was a design goal for the language and platform API writers have been doing it for decades. they even relented and made "#include <standard C header.h>" 100% legal again because it was colossally stupid to conditionally #include <cstdio> vs #include <stdio.h> in, say, a common header file

let's say that C and C++ share a common subset, ok? nevermind that the "subset" is like 99% of C

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
objective c, however, is a strict superset of c :chord:

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 saw you committing c code. objective c only please"
- my boss

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
also: id converting silently to BOOL

Cybernetic Vermin
Apr 18, 2005

pseudorandom name posted:

except it doesn't

we might as well argue theology at that point though for all the practical relevance this has

pseudorandom name
May 6, 2007

integer overflow and type based alias analysis both have undefined behavior which does not behave like the compilers of yore

Nomnom Cookie
Aug 30, 2009



hackbunny posted:

"i saw you committing c code. objective c only please"
- my boss

that sounds like a good dadjoke

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

pseudorandom name posted:

integer overflow and type based alias analysis both have undefined behavior which does not behave like the compilers of yore

signed integer overflow does

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

hackbunny posted:

also: id converting silently to BOOL

c's legacy is all types silently converting to other types, forever

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
*silently converts ur resume to teh goatman*

Nomnom Cookie
Aug 30, 2009



Otto Skorzeny posted:

*silently converts ur resume to teh goatman*

should've avoided undefined behavior in ur resume writing program

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
message based oop is the best oop tbh

also multimethods are cool

but tying data to behaviour is not all its cracked up 2 b

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

Kevin Mitnick P.E. posted:

should've avoided undefined behavior in ur resume writing program



heh :golfclap:

MeruFM
Jul 27, 2010
the problem would ahve been clearer if they showed what it actually looked like. and why 1 liners without brace is retarded.

code:
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail;
Because otherwise lol if your 1 liner takes 2 lines.

Adbot
ADBOT LOVES YOU

Nomnom Cookie
Aug 30, 2009



the bug wouldn't have been possible if SSLHashSHA1.update threw an exception instead of returning an error code

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