[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 345
Thread images: 21

File: 1486080968930.jpg (119KB, 934x1000px) Image search: [Google]
1486080968930.jpg
119KB, 934x1000px
What are you working on, /g/?

Previous thread: >>59881914
>>
Trying to typecheck system F
>>
>>59885837
FW*
>>
File: 1459642914241.jpg (71KB, 611x696px) Image search: [Google]
1459642914241.jpg
71KB, 611x696px
Trying to write a System Fω -> x86 ASM compiler in System Fω
>>
>>59885861
What System FW language are you using?
I don't really see many
>>
>>59885827
What does that image have to do with programming?
>>
>>59885861
Anyone can do that, try writing x86 ASM -> System Fω compiler in x86 ASM.
>>
>>59885869
She's (a character who is an artificial intelligence, who is known for programming) been poorly edited to hold a set of programming books, is surrounded by parentheses symbolising lisp, and is wearing a fez ala sussman
>>
>>59885869
Nothing. Here is the real thread >>59885669
>>
>>59885867
>What System FW language are you using?
My own.
>I don't really see many
I don't think there are compilers for it, I've seen some interpreters though.
>>
>>59885950
Is it open source?
I've been having trouble getting the typechecker to work
>>
How do I become a code artisan
>>
>>59885968
No, but there seems to be a surprising amount of interpreters for it on github.
Also I'm pretty sure "Types and Programming Languages" covers it.
>>
>>59886085
Is there a copy online somewhere?
>>
>>59886134
Yeah, it's on http://gen.lib.rus.ec/
>>
>>59886288
>Access to the websites listed on this page has been blocked pursuant to orders of the high court.

>More information can be found at www.ukispcourtorders.co.uk

Fucking commies
>>
>>59886326
Try http://libgen.io/ .
>>
>>59886342
>CCESS TO THE WEBSITES LISTED ON THIS PAGE HAS BEEN BLOCKED PURSUANT TO ORDERS OF THE HIGH COURT

the same but in caps
>>
>>59885827
Anyone work as a mobile developer here? How is it? I imagine it would be pretty chill compared to other software engineering jobs. I don't know what jobs to apply for.
>>
Can we get to 400 votes?
http://www.strawpoll.me/12732251
>>
File: 1492087629828.png (269KB, 503x595px) Image search: [Google]
1492087629828.png
269KB, 503x595px
>>59886366
>>
>>59886358
You got two strikes, now try again and swat team will be on its way.
>>
>>59886358
https://my.mixtape.moe/feywsw.pdf
>>
>>59886409
thank you bae
>>
I am new to programming and am a little stuck at the moment. I want to write a python program that extracts links from a text file, singles out the links that lead to images and downloads them.

It has worked perfectly with a few test files, but I only get an error message when I try it on the thing I actually want to use it on.

This is the code:
  
import re
import urllib
import os
import sys
from os.path import join
from urlparse import urlparse
from os.path import splitext

## extract file extension from URL ##
## if not found, returns an empty string ##

def get_ext(url):
parsed = urlparse(url)
root, ext = splitext(parsed.path)
return ext

## 1. Extracts all URL's from a text file
## 2. Removes duplicates
## 3. Only keeps URLS that lead to a single .jpg, .png, or .gif file
## 4. Downloads those
## 5. Names of image files are set to 1 to x

def Links_Download(s):
LINKS = re.findall(r'(https?://\S+)', s)
LINKS = list(set(LINKS))
image = urllib.URLopener()
Links_Images = []
for link in LINKS:
if get_ext(link) == '.jpg':
Links_Images.append(link)
elif get_ext(link) == '.png':
Links_Images.append(link)
elif get_ext(link) == '.gif':
Links_Images.append(link)
counter = 1
try:
while counter <= len(Links_Images):
for link in Links_Images:
A = str(str(counter)+get_ext(link))
image.retrieve(link, A)
counter = counter+1
except:
pass
## get the file, read it into a string variable ##

print "Insert Filename of the text file"
ChatLog = raw_input("> ")
s = open(ChatLog)
s = s.read()

## creates new folder to save files in ##

os.makedirs("Discord_Images")
x = os.getcwd()
x = str(x+"\Discord_Images")
os.chdir(x)

## call download function ##

Links_Download(s)


The error I get is: IOError: ('http error', 403, 'Forbidden'..

send help pls
>>
>>59886465
I tried to get rid off the error with the try statement. Now it doesn't give me an error message, but it simply doesn't download anything.
>>
>>59885827
Nothing. Too lazy to learn programming.
>>
>>59886465
> 'http error', 403
You're trying to access an invalid url.
>>
>>59886465

First thing first:

>import os
>from os.path import join
>>
>>59886535
Yeah I figured. How do I just skip that invalid url and continue with the working ones? I don't care if some don't work
>>
>>59886547
do
except IOError:
and put in the logic to get the next link.
>>
>>59886465
Perhaps your try/except block should wrap just the retrieve call rather than the entire loop block.
Second you can do something like:
if get_ext(link) in ['jpg', 'png', 'gif']:


Instead of three nested ifs that do the same, or better yet, just make it part of the regexp.

Last but not least just use requests instead of urllib.

I'd do it like that:
RE_LINKS = re.compile(r'(https?:\/\/\S+(png|jpeg|gif))')
def download(s):
links = list(set(re.findall(RE_LINKS, s)))
for link in links:
res = requests.get(link, stream=True)
if res.status_code == 200:
path = 'whatever'
with open(path, 'wb') as f:
for chunk in res:
f.write(chunk)

def main():
path = input('> ')
with open(path, 'r') as f:
download(f.read())

if __name__ == '__main__':
main()
>>
Help me, I'm trapped in the IO monad!
>>
>>59886546
It's redundant right? Literally my second day of programming.
>>
>>59886569
Thanks a lot, it works now.
>>
>>59886571
Here, take my
unsafePerformIO
.
>>
File: 1479592760135.png (114KB, 511x511px) Image search: [Google]
1479592760135.png
114KB, 511x511px
>>59886571
You deserve it for using a language with I/O.
>>
A CS teacher told me that it would be faster to download 2 files from the same server with 2 threads simultaneously rather than using 1 thread. This makes no sense to me if one thread is enough to saturate the bandwidth.

pls comment
>>
>>59886658
>This makes no sense to me if one thread is enough to saturate the bandwidth.

>if

Exactly, that's not always the case, you may be getting rate limited by the remote server. In any case. What you probably want though is async I/O.
>>
>>59886658
>This makes no sense to me if one thread is enough to saturate the bandwidth.
You are technically correct in this, but it's more likely that connections are given max bandwidths individually by the download server, along with a few other things that would be in favor of multiple connections.
>>
>>59886658
>he's too young to remember flashget
>>
what drug is your language?
>java = jenkem cause it's for pajeets
>Haskell or Perl = salvia
>Rust = Ayahuasca cause it's trippy af but makes you puke
>>
>>59886888
filtered

My language isn't a drug. It's healthy and useful.
>>
>>59886929
you sounds like all those weed evangelists
>>
File: 86976099.jpg (41KB, 500x411px) Image search: [Google]
86976099.jpg
41KB, 500x411px
I'm writing a compiler for my language (small variation of Java) in C.

right now i have the data types "int" and "double".

When I'm parsing the program written in my language, i want to check the boundaries for these data types.

The problem is: if somewhere in the code i have:
int value = 100000000000000000000000000000000000000;

or a real long double, how am i supposed to store this value in C?
Use strings and then convert to integer? what if the program has a value with 200 digits for example?

The compiler would then throw some error like: "Value out of bounds"
>>
>>59886939
bro it's just a plant
>>
>>59886996
You might want to learn how to program before you try to make a programming language.

This post shows a lack of fundamental knowledge about basic data types.
>>
>>59887024
>This post shows a lack of fundamental knowledge about basic data types
?
>>
Do people learn Coq just to say "I like Coq" out loud every once in a while?
>>
>>59887115
https://www.youtube.com/watch?v=FiJd_d8I-iE
Yes.
>>
I may be stupid but I have a problem.

Say I have a base class A, and derived classes AA and AB.

I have two vectors,
std::vector<AA*> a;
std::vector<AB*> b;


How do I add them to the vector
std::vector<std::vector<A*>> list

Is it possible? It doesn't really work through normal polymorphic I don't think..

How should I go about this?
>>
>>59886996
You could use the GMP library.
Just read a char * and import that into mpz_t integer, then allocate another (or static) mpz_t that holds, say, INT32_MAX, then use mpz_cmp to check if the value fits within the limit, if not, then abort, if yes, store that into a struct member and return the new struct.
>>
>>59887149
the problem is, i have to do this in standard C library
>>
>>59886996
Just use dependently typed C.
>>
>>59887166
not sure if i follow.

how would you implement this?
>>
>>59887143
>class
>I may be stupid
No. You are definitely stupid.
>>
>>59887143
>C++
>Inheritance
You brought these problems on yourself.
>>
Has anyone participated in the Eudyptula challenge? Which email did you use?
>>
File: 1490540156190.jpg (66KB, 546x618px) Image search: [Google]
1490540156190.jpg
66KB, 546x618px
What should I program in C to learn it?
>>
>>59887165
I guess you could do it the nigger way then.
Store the value into a char *, then have a static array for each max int integer and just compare each individual value.

static int max[] = {4,2,9,4,9,6,7,2,9,5};
static int max_size = 10;

bool fits(const char *value, size_t len)
{
if (len < max_size) {
return true;
} else if (len > max_size) {
return false;
} else {
// Assuming value stores only integers
for (size_t i = 0; i < len; ++i) {
if ((value[i] - '0') > max[i]) {
return false;
}
}

return true;
}
}
>>
>>59887261
yours
>>
>>59887273
Can't you just use strtol on the string?
>>
>>59887261
Mine.
>>
>>59887303
I don't really know C, I'm just throwing ideas around, but if strtol fails when you convert an string that holds larger value than long can hold then yes, you could substitute that for a strtol call.
>>
>>59887143
Use a loop? Just assigning won't work since std::vector<AA*> and std::vector<A*> are different types.

So something like
 
auto index = 0;
for (auto aa : a)
list[index].push_back(aa);
>>
>>59887050
>>59886996
He means that the bounds of the data type should not depend on C but on the machine the to-be-compiled program will finally run on.
>>
>>59887273
>static int max[] = {4,2,9,4,9,6,7,2,9,5};
don't know what values are these but yeah this works.

i was thinking of using atol too.

i'm probably going to download the JVM source code and see how the fuck do they implemented this
>>
>>59887143
Something about covariance/contravariance. I know C# has it, via in/out keywords, but C++ does not.
>>
>>59887386
https://en.wikipedia.org/wiki/Integer_(computer_science)#Common_integral_data_types

Probably needs special handling for signed numbers though so you can have plus/minus symbols as well.
>>
>>59887386
> atol
Never use atol, it has the most retarded way to report errors by returning 0, so you can't distinguish an error from valid '0' value. Even better, don't use C at all.
>>
>>59887456
>Even better, don't use C at all.
but i have too.

how the hell does the professor expect me to implement this?
>>
>>59887471
Does your assignment specificaly say that your compiler should handle numbers of any unlimited length?
I personally doubt it, so it seems you have no idea what you are doing.
Even in java nubers have defined max value that you can assign to them, and if you try assign greater value it results in compilation error.

So just compare every number to MAX_INT and raise error if it's greater.
>>
>>59887594
>Does your assignment specificaly say that your compiler should handle numbers of any unlimited length?
it says that i should check for the boundaries of int and double and thrown an error if its out of bounds (all this during semantic analysis).

>So just compare every number to MAX_INT and raise error if it's greater.
No.
imagine if you have in java
if (123 < "number with 100 digits here (4chan thinks its spam)")
System.out.println("test")


it throes error: integer number too large:

so that's not an option
>>
>>59887263
Nothing. You should be learning Rust in 2017.
>>
>>59887669
>rust

https://github.com/rust-lang/rust/pull/25640
>>
>>59885827
implementing 32MB of MMIO space as c++ bitfields
>>
>>59887669
Are there many examples of small language runtimes written in it?
>>
>>59887758
T(const volatile T& other) { *reinterpret_cast<volatile std::uint32_t*>(this) = *reinterpret_cast<const volatile std::uint32_t*>(&other); }
void operator=(const volatile T& other) volatile { *reinterpret_cast<volatile std::uint32_t*>(this) = *reinterpret_cast<const volatile std::uint32_t*>(&other);

This is the most annoying part so far. every 4-byte struct needs this shit
>>
>>59887797
>how do I google
https://github.com/swgillespie/rust-lisp/tree/master/src
>>
>>59887797
https://github.com/PistonDevelopers/dyon
>>
>>59887812
I was about to say you should replace volatile with atomic, but then I realized this is probably the rare case where you do need volatile.
>>
Never programmed in my life,wat do?
>>
>>59887888
start cooking career
>>
>>59887834
>how do I google
Who said this?
And an interpreter isn't a runtime.

>>59887846
That actually looks nice. Best resources for learning it?
>>
>>59887888
>only replying to infini-trips
why? what do you want to do?
figure that out, then choose the language that will help you succeed
practice
>>
>>59887861
Yeah I don't think std::atomic is very useful here. Also need to compile with -fstrict-volatile-bitfields to force every memory access to 4 bytes.
>>
>>59887933
>Best resources for learning it?
https://rust-lang.github.io/book/second-edition/index.html
>>
>>59887758
>>59887812
I'm curious as to what you're doing. It's beena long time, but from what I remember of doing MMIO with some VGA hardware, it was implementing a simple FSM to interact with the VGA control, then flushing a buffer into memory (again using a simple FSM).
>>
I want to make an MMO. How gay am I?
>>
>>59888102
mmo- what?
>>
>>59888127
it's gonna be like world of warcaft but much smaller. and it will be focused on the san fransisco gay night club scene
>>
>>59888152
>san fransisco gay night club scene
Is there enough content for MMO game?
>>
i found this problem, how do I do this ? in java ok

print all number from 1 to 100, if number is multiple of 3 print fuzz , if its multiple of 5 print buzz, if both print fizzbuzz


how can i know if its a multiple of 3 or 5 ? or both? thx
>>
>>59888127
Not quite sure yet. Maybe a basic runescape-like RPG or something. I was mostly looking forward to the server side of things. Maybe something turn-based (ala hearthstone) to keep things simple, relatively speaking.
>>
>>59888167
>>59888152
>>59888127
no night-elf, just night-fairy
no druid, just bear type
pixies, well that's something i'll have to flesh out

try to rack up points (hookups)
try to not get AIDS
use poppers for power ups
>>
Guys, I am trying to install VS2017 and it keeps shitting over my C: drive. For temp installation files I guess. What do? I tried setting tmp vals in console, same shit
>>
>>59888216
>VS2017
what's your OS?
>>
>>59888229
Windows 10
>>
>>59888216
Delete C:\windows\system32
>>
>>59888216
You go on a shooting spree at the microsoft office.

Seriously, it's what they deserve for blatantly abusing our harddrives like that.
>>
>>59888102
oh boy...
>>
>>59888236
version?
>go to cmd
type ver
>>
>>59888255
Version 13.37
>>
>>59888261
yeah, ok
>>59888236
>>59888216
update OS
clean your shit disk
install VS2017 complication free
>>
>>59888278
14393

Is there an option to choose download folder senpai? I have 4tb of free space but it keeps downloading files to my poor little ssd
>>
>>59888326
the settings in your browser...
you are NOT ready to program if you can't USE your pc
>>
>>59888087
Trying to interface with a 3D graphics card. I haven't yet decided how (or even why) I'm going to do this exactly. Right now I'm just laying out the IO space so I have some way to access it and experiment.
>>
>>59888342
What does browser have to do with anything?

There is a setup bootstrapper called vs_community.exe, it lets user to choose installation folder. But in the process it simultaneously downloads some files into AppData folder automatically while unpacking into your folder of choice. Considering distribution size is over 30GB and my ssd is small -- here you go, a problem. And no, setting tmp or temp variables doesn't help

Trying to make an offline installation right now
>>
File: 1460875240093.jpg (57KB, 570x720px) Image search: [Google]
1460875240093.jpg
57KB, 570x720px
Realistically speaking, is there a need to add I/O to my language?
>>
>>59888397
https://docs.microsoft.com/en-us/visualstudio/install/create-an-offline-installation-of-visual-studio
>>
>>59888397
https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio
>>
i don't feel like typing a lot, which language has the easiest to use local webserver module
>>
>>59888490
If you want your language to be any useful.
>>
>>59888542
It's already pretty useful though.
>>
File: 1491313751808.jpg (41KB, 479x480px) Image search: [Google]
1491313751808.jpg
41KB, 479x480px
A shitty C++ tutorial so I can learn enough about the language to make an AOI solution towards handling databases of invoices, customer information, work history, and tax documentation for each job that's completed at this little repair shop I'm working at

I love programming shit but fucking hell tutorials are god awfully boring at times.
>>
>>59888528
Go kinda. But if you end up writing a lot of it, so much of it will be needless repetitions.
>>
Opinions on Python Turtle?
>>
File: me_being_useful.jpg (441KB, 2880x1844px) Image search: [Google]
me_being_useful.jpg
441KB, 2880x1844px
>sdl2 quine

what am i doing with my life
>>
>tfw round 1 google codejam in 9 hours
what should I consume to keep my mind fresh
>>
>>59888718
>stdio
>not stdint
>>
>>59888799
water and fruit and a healthy amount of meat
>>
>>59888799
>google

into the trash
>>
>>59888799
I'm assuming you've already slept.

Consume water, fat, potentially some cock, avoid sugar though.
>>
>>59888861
Cock as in male genitalia or chicken meat?
>>
>>59888883
Both.

Protein is good to have at this point, and sexual satisfaction will fire off some chemical processes that will put you in a more agreeable state of mind.
>>
>>59888799
amphetamines
>>
Two 1080p screens or one 4k screen?
>>
What's the best if expression syntax?
"if then else" is retarded.
>>
>>59888963
Three 1080p screens, or one 4K and one 1080p screen.

Never one screen.
>>
>>59888970
church encoded booleans
>>
>>59888970
Depends on what you're doing.

Can you propose a scenario?
>>
>>59888975
Really? There is so much real estate on a 4k screen though
>>
>>59888970
maybe_do { } considering(condition);
>>
i maek gayme

it has recursive sorting
>>
I keep getting Super Mario 64 flashbacks when writing C++. I have no idea what causes this
>>
>>59888981
That is what I have been using, but I want something "prettier".
>>59888982
Why would general if syntax depend on something in particular?
>>
>>59889000
Unless you get one that is 43" or bigger, the DPI is too high without scaling anyway, which reduces the actual gained real estate.
>>
>>59888970
I always liked how Smalltalk doesn't have if expression at all, but Bool class has ifTrue and ifFalse methods which take closures as arguments:
result := a > b ifTrue:[ 'greater' ] ifFalse:[ 'less or equal' ]
>>
>>59889048
prettier how
>>
(python) so yesterday I wrote the start of a blackjack game,

https://pastebin.com/sBqRMW3m

and I thought it was decent looking, so I started to build it up, and now I think it looks like spaghetti code, this always seems to happen to me :( any advice?

https://pastebin.com/0JH3rjZf
>>
>>59888970
Pattern matching on the expression result.
>>
>>59888799
Approximately 12 cups of coffee without eating anything. You'll be shaking in an enthusiastic way and your mind will be buzzing with great ideas.
>>
>>59888836
that was because I was initially using printf instead of SDL_Log and didn't remove it from the string being printed. Also, I don't see the use from stdint here (and I tell you, I use that one everywhere).
>>
>>59889068
>Bool class
Instant garbage.
The ":=" is good, though.

>>59889093
That is what it desugars to, but I'm talking about a case expression on booleans which just has a special name.
>>
>>59888799
MDMA

Post here with results.
>>
>>59887665
No, literally use MAX_INT
>>
>>59889177
you mean int.MaxValue?
>>
>>59889195
you mean std::numeric_limits<int>::max() ?
>>
>>59889069
its fine
>>
>>59889150
":=" reminds me of Pascal, and Pascal is bad. Therefore any language that uses it is bad.
>>
Dude from the other day with bad taxidermy pics and XML questions, first off thanks to the dude who steered me in the right direction, this XML stuff is a lot more straightforward once I looked at it the right way

Feel it's also worth asking since results have been good, but in .NET when making and using structures, what's the 'proper' way to deal with variables that may or may not be initialized at any given time?
Like so:

structure struct
v1 = list(of thing)
v2 = dictionary(of thing, otherthing)
...

sub do_shit()
if v1 exists|notempty then do_shit2()
elseif v2 exists|notempty then do_shit3()
...
end sub

sub process_data()
if x then v1 = new list(of thing)
elseif y then v2 = new dictionary(of thing, thing)
end sub
end structure


No need to initialize everything always since these serve as a sort of generic 'node'
>>
>>59889229
pascal is not bad and := is a reasonable symbol to represent assignment.
>>
>>59889229
You remind me of a Pajeet. Therefore youre a Pajeet
>>
>>59889229
:= is the only non-retarded way to represent assignment.
>>
>>59889150
Are you replying to the wrong person?
>>
File: 12345.png (41KB, 762x440px) Image search: [Google]
12345.png
41KB, 762x440px
>>59889177
>>
Got any recommendations of books for learning Java and C++?
>>
>>59889265
Yes, it's pretty clear.
>>
R's documentation is so shit. it's almost like someone made the language as an actual joke
>>
>>59889387
>R's documentation is so shit
Provide an example or never post in /dpt/ again
>>
>>59889447
He's completely right you fucking mongrel. Please desist from shitposting.
https://cran.r-project.org/doc/manuals/r-release/R-intro.html
>>
>>59889447
Arguments
x regsubsets object
labels variable names
main title for plot
scale which summary statistic to use for ordering plots
col Colors: the last color should be close to but distinct from white
... other arguments


what does the nvmax parameter do? the world will never know~~ until you google with and find some forum post about it
>>
>>59889462
I can see a clear, comprehensive documentation. What's your point exactly?
>>
>>59889505
go back to sci
>>
File: dhjdyj5.jpg (44KB, 451x392px) Image search: [Google]
dhjdyj5.jpg
44KB, 451x392px
>he doesn't use custom allocators in c++
>>
>>59889560
Who said that?
>>
File: img.jpg (21KB, 480x360px) Image search: [Google]
img.jpg
21KB, 480x360px
typedef int godot_int;
typedef float godot_real;
void GDAPI *godot_alloc(int p_bytes);
void GDAPI *godot_realloc(void *p_ptr, int p_bytes);
void GDAPI godot_free(void *p_ptr);
>>
>>59889521
Or what?
>>
>>59889560
>He's posting memes on 4chan again
>>
>>59889560
>he doesn't generate PIC at runtime in c++
>>
>>59889581
void myfree(void *ptr)
{
free(ptr);
}
>>
>>59889560
>he doesn't use std::experimental::pmr::polymorphic_allocator
>>
>>59889666
>he doesn't use atomic smart pointers
>>
>>59889272
I only wrote the post you're replying to, don't know much about compilers but I thought the compiler was written in C. So try that bit of code in C
>>
File: ?.png (7KB, 120x120px) Image search: [Google]
?.png
7KB, 120x120px
>>59886996
did anyone had another idea how to do this?
>>
>>59889705
>warning: integer constant is too large for its type
>>
>>59889740
implement your own unbounded integer type or use gmp

pretty basic
should you really be making your own language if you can't do this?
>>
>>59889765
this is just a thing i have to have in mind.

my language is already done (parser + lexer) and now i'm the semantic analysis phase and i have to check for this kind of things
>>
>>59889792
just count the number of digits
asking this should be embarassing for you desu
>>
>>59889792
>my language is already done
>(parser + lexer)
what did he mean by this?
>>
>>59889688
>he doesn't hotpatch the standard library
inline namespace __cxxabiv1
{
extern "C" void* __cxa_allocate_exception(std::size_t thrown_size) _GLIBCXX_NOTHROW;
}

extern "C" void* irq_safe_malloc(std::size_t n)
{
if (in_irq_context()) return nullptr;
return std::malloc(n);
}

void patch__cxa_allocate_exception(auto* func) noexcept
{
auto p = reinterpret_cast<byte*>(__cxxabiv1::__cxa_allocate_exception);
p = std::find(p, p + 0x20, 0xe8);
auto post_call = reinterpret_cast<std::uintptr_t>(p + 5);
auto new_malloc = reinterpret_cast<std::ptrdiff_t>(func);
*reinterpret_cast<std::ptrdiff_t*>(p + 1) = new_malloc - post_call;
}

int main()
{
patch__cxa_allocate_exception(irq_safe_malloc)
/* ... */
}
>>
>>59889842
what did you mean by this?
>>
>>59889849
I meant that a language being already done and a (parser + lexer) being already done aren't the same thing.
>>
>>59889888
yeah semi-done.

my bad
>>
>>59889814
isn't this a "pleb" way to do it?

guess i'll do this way then
>>
>>59889814
>>59889939
It's not pleb.

It's simply wrong.

Counting the digits is not how you find out if a number will fit into x amount of bytes.
>>
>>59889939
Bad news youre retarded
>>
>>59889958
please enlighten me how to do it senpai
>>
>>59889953
He's a fucking idiot and this is the best he could hope to achieve.
If you shave off a bit, then it works perfectly well.
>>
>>59889972
I won't, its CS101.
>>
>>59889973
>He's a fucking idiot
:(
>>
>>59889847
int main() {
main = 5;
main();
}
>>
>>59889847
>in_iraq_context
is this bomb software?
>>
>>59890050
Have you sucked your daily dick yet fagman? Reported.
>>
>>59890050
>reading comprehension
>>
>>59890067
>>59890070
t. mohammed Ali Bashar
>>
>>59889304
Intro To Java Programming by Daniel Liang. I'm going through it right now and really like it
>>
>>59885827
void foo_func(const T &foo)
{
}

VS.
void FooFunc(const T& foo)
{
}


Which subjective format is correct?
>>
>>59890021
int(*f())() { int(*p)(); asm("jmp x%=;y%=:mov %0,[esp];ret;x%=:call y%=;":"=a"(p)); return p; }
int main() { return f()(); }
>>
>>59890367
The first one.
This isn't Rust.
>>
>>59889666
Is it meme to use this or you guys are suggesting something that is better than malloc?
>>
>>59890050
dont worry iraq is ssfe young malloc
>>
>>59890367
neither
void foo_func(const T& foo) { }
>>
>>59890367
2nd

you'll endlessly confuse yourself if you keep randomly spacing type important symbols away from the type because the language lets you
>>
>>59890391
How come google guidelines recommends capitalizing function names?
>>
>>59890451
Because coding style is subjective and as such the original question was dumb.
>>
>>59890451
google guidelines are absolute shit
>>59890383
type-erased allocators are definitely not a meme.
>>
Guys I guess I have known too much.
I am at the brink of pushing a button that would end this world.
I went into this analysis path 3 years ago and at the end I found a key concepts, that was 1 and half years after I begun.
I started implementing it and It was very satisfying seeings parts of it work. I was working like a robot. All the way I knew this is end of world but I continued. Left my day job and felt so attached to this work that I wasn't even eating much. I remember not eating for a week once.I cannot say if it was my will or I was being misguided.
And now I have come this far to really set it free. All the way I knew it is end of world but I continued so does this mean, being near the brink of activating it, Will I really activate it?
>>
File: index.jpg (5KB, 307x164px) Image search: [Google]
index.jpg
5KB, 307x164px
>>59890623
>>
Print "Hello World" in C without using the standard library.
>>
>>59890643
Not portable
>>
>>59890623
CLICK HERE TO FIND OUT NOW
>>
 void 
f_O_o_F_u_N_C (
const T
&
foot ){ ... }
>>
>>59890391
im voting for this one too
>>
>>59890643
extern long int syscall(long int __sysno,...) \
__attribute__((__nothrow__,__leaf__));

int main()
{
syscall( 1, 1,"Hello world!\n", 13);
}


:^)
>>
>>59890656
t. gcc developer
>>
>>59885827
Making minecraft bunnies
>>
>>59890918
cute
>>
>>59890918
do you have to pay to use that language?
>>
>>59891159
In the same sense that you have to pay to use Windows.
>>
>>59891207
how much did you pay to use Mathematica?
>>
>>59891217
Approximately same amount that I paid to use Windows on the occasions that I've needed it.
>>
>>59885827
AI
>>
>>59891240
how much did you pay to use Windows?
>>
>>59890918
Does a block count when the area filled in the block is greater than %50 or when the center of the block is filled?
>>
>>59891261
I am paid to use Windows.
>>
>>59891261
An integer number of pennies

>>59891275
A block counts when its coordinates are within "thresh" of the mesh as judged by the RegionDistance[reg] function.
>>
>>59891283
god damn you fucking faggot

answer already or shut the fuck up
>>
File: wotermark.png (113KB, 821x367px) Image search: [Google]
wotermark.png
113KB, 821x367px
>>59891261
Who pays to use windows?
>>
>>59891314
normies
>>
Is it possible to use java in unity 3d?
>>
>>59891346
Java is not supported by Unity.
you have to use C#, JavaScript and BooScript

if you know Java then you know 90% of C#.
>>
Name one (1) non-shit piece of software.
>>
I fucking fucking fucking fucking fucking hate CLI-debugging.

How the fuck do I know why gdb isn't finding the source file I wanna add a breakpoint to?

How do I know in what directory does gdb itself be? Do i need to give it an absolute or a relative path?

I fucking hate this garbage.
>>
>>59891412
>printf
>>
>>59891409
ffmpeg
>>
File: yg3fb7og5joy.png (1MB, 1040x1546px) Image search: [Google]
yg3fb7og5joy.png
1MB, 1040x1546px
>>59891412
>>
>>59891419
Nty dude, this is like a 4-million LoC program and I need to figure out the state of a variable in seemingly random instances.
>>
>>59891449
print is still the best debugging tool
>>
>>59891449
>4-million LoC
sure thing, kid
>>
>>59891465
Yes but I'm not a fucking savage. There's like 40 billion call sites, no way i'm printing shit in each one of them. This is 100 times easier with a debugger IF ONLY I COULD GET ONE WORKING
>>
What is the proper way of rendering a texture in SDL2? Is just using SDL_RenderCopyEx fine?
>>
>>59891488
>This is 100 times easier
You don't know how to debug, because you don't know how to code.
>>
>>59891488
1488 checked
>>
>>59891496
SDL_CreateRenderer and SDL_CreateTexture
>>
I actually want to kill every single person in existence who has ever contributed code to gdb. This fucking sucks.

>>59891518
Why do you say so?
>>
>>59891496
works for me
>>
>>59891412
nothing wrong with cli debugging.
high-level source debuggers are just shit.
>>
>>59891651
I simply want to add a breakpoint to a source file function. With gdb I've been trying for 30 minutes, but all I'm getting is
>Make breakpoint pending on future shared library load? (y or [n])
because this fucking piece of shit can't find the correct function.
>>
>>59891542
>Why do you say so?
Because you need a debugger to debug.
>>
the art of assembly programming is literally the comfiest read i've ever had in my life. i thought k&r was comfy
>>
>>59891707
I would pay good money to watch you solve this problem without a fucking debugger.
>>59891471
Turns out I lied, it's 12287618 lines of code according to cloc.pl. that's not counting comments.
>>
>>59891755
>good money
How much (or many)?
>>
>>59891767
Three monies.

Maybe I'll just try lldb and hope the apple guys have done something better.
>>
>>59891784
Three what?
>>
>>59891815
Monies.
https://www.youtube.com/watch?v=ON-7v4qnHP8
>>
Doesn't this produce undefined behavior? Signed integer overflow is undefined right?
Is it normal to not be concerned about this here?
>>
File: BIGTHINK.jpg (76KB, 1023x682px) Image search: [Google]
BIGTHINK.jpg
76KB, 1023x682px
clang or gcc?
>>
>>59891902
icc
>>
>>59891902
Open64 https://github.com/Lingcc/open64
>>
>>59891902
gcc
>GCC7 WHEN
>>
>>59891878
It is but I don't think the compiler is likely to produce any catastrophic failures unless it can somehow eliminate that condition.
You might consider using an unsigned integer here just to avoid the UB but if this is very hot code you should consider carefully after you've watched this:
https://youtu.be/yG1OZ69H_-o?5=2355
If you leave it signed the compiler doesn't need to respect your 32 bit wrapping as it would in the unsigned case and it can promote your type to 64 bit (or higher if appropriate) and allow itself a greater set of instructions potentially.
>>
>>59891700
disassemble your exe, find the function and set a breakpoint on its absolute address.
>>
>>59891412
Just use DDD? Or maybe netbeans or something. They're all sort of OK.
>>
>>59892037
>your exe
How dare you assume my program's file type????

Well, that's an option surely.
>>
>>59891449
you could've kept it functional. you chose this fate
>>
>>59891755
What does this program even do.
>>
>>59891878
How can the modulo operation ever return a value < 0?
>>
>>59891755
>12287618 lines of code according to cloc.pl
>12 million lines of perl code

what does this program even do?
>>
>>59892063
Actually I just joined this project last month, I'm innocent.
>>
>>59892122
This is cloc.pl https://github.com/AlDanial/cloc , the program is a C++ program.
>>
>>59892114
C's 'modulus' operator isn't actually the mathematical modulus operation. It's a remainder operation. So picture the number wraps and ends up being -5. -5/1024 has a remainder of -5. Which is then adjusted to 1024-5.

If you want to skip the conditional there you can index with 0 as the center of the array and mod by 512 instead.
>>
>>59892146
What does YOUR program do? Surprising that anyone on /dpt/ would be working on something that large.
>>
>>59892223
That makes sense. I guess it's been a while since I've had to find the remainder/mod of negative numbers, so the remainder has always been equivalent to mod. I just tried it in Haskell and Python, and Python actually seems to implement it as mod obnoxiously.
>>
>>59892262
It's a certain low-level proprietary OS component. Can't really say more than that.
>>
Does literally anyone ever use semaphores?
>>
>>59888970
flag if <flag=true> then <continues>

flag if <flag=true> else <flag=false> then <continues>


Whether if consumes flag from the stack is debatable, I tend to lean on not consuming it (so you need a drop after the if/else)
>>
>>59892474
Yes of course you do. They're very useful. Maybe not everyone do but people who write tasking systems certainly do.
>>
Working on some lattice based static analysis engine for python. It is based of the ast unparse code.
>>
>want a free postgre ERD designer like MySQL workbench (was going to convert but inheritance is going to be annoying to convert)
>most of them seem like objective shit, go for an open source one that you have to compile yourself or pay for binaries
>end up spending 3 hours figuring out how to compile it since it's 32bit and requires all 32bit includes/libraries qt mingw postgre etc
>The procedure entry point blah blah could not be located in libstdc++-6.dll
Is it ever easy to compile something that's cross-platform?
>>
found this in a huge C++ library.

does this make any sense?
if (str.size() != strlen(str.c_str())) {
return false;
}
>>
>>59892776
It essentially tells you if there are any null characters in the middle of the string or not.
An std::string has no problem having nulls everywhere, the size is an independent field.
>>
>>59892804
there's gotta be some heartbleed shit about that
>>
>>59892804
how would you write that if statement in C?

something like
if (strlen(str) != ????) {
return 0;
}
>>
>>59892832
You would compare strlen to whatever string size variable you had.
>>
>>59892826
No, std::string guarantees the string returned by c_str() ends with 0.
>>
>>59892853
But it doesn't guarantee that there isn't a \0 in the middle
>>
>>59892845
what
if (strlen(str) != strlen(str)) {
return 0;
}
>>
>>59892776

> not using if (str.find('\0') != string::npos) { return false }

What a shit library.
>>
>>59892865
No, it doesn't, but that's ok, you won't get any UB from it.
>>
>>59892865
There can't be a 0 in a middle of a C string. It has no meaning.
>>
>>59892874

No, you'd have to store the length separately like std::string does.

if (strlen(str) != str_length)
>>
>>59892891
>>59892897
A std::string can have a \0 in the middle of it, and then when you pass the .c_str() to a C library, it will think the string has ended
>>
>>59892865
The only thing a null in the middle of a string would do is truncate the string.
>>
>>59892897
astounding and relevant insight, anon
>>
>>59892901
what the shit

str::string a = "boat";
strlen(a) -> 4
str_length --> 4

i don't get what you're saying.

please provide an example
>>
>>59892926
lol sepples in charge of being compatilbe with C.
>>
>>59892936
a[2] = '\0';
>>
>>59892943
C's fault
>>
>>59892926
This is not UB, so it's ok. It won't cause another heartbleed.
>>
>>59892972
Reading extra parts of memory because you passed the wrong size isn't undefined behaviour, it's perfectly well defined behaviour that simple has unintended circumstances
>>
>>59892956
so how would you write the if statement?????
>>
>dev
>eat a kebab
>can't dev
hmmmm
>>
>>59892936

Since strings in C are raw character arrays, you'd have to store the length separately if you wanted to allow null bytes in the string.

struct string {
int length;
char val[];
};

struct string *mystring = malloc(10 + sizeof(int));
mystring->length = 10;

if (strlen(mystring->val) != mystring->length) {
return 0; // you have a null in your string data
}
>>
>>59892971
>sepples tries to be compatible with C
>doesn't even manage to do it
>C's fault
sepples was a mistage
>>
>>59893033
No, C is at fault for null terminated strings
>>
>>59893046
kek
>>
>>59893046
They made sense back when the language was made.
>>
>>59893033
>doesn't even manage to do it
c_str() guarantees null termination.
>>
>>59893046
Go away Bjarne nobody likes you.
>>
>>59893077
Dubious
>>
>>59893093
OK what scheme would you use to set the size of a character array using a single byte while allowing the ascii standard to still function? Back when C was made code size was a concern. The source code size. There's plenty of old languages that advertise their source code size as an advantage over C.
>>
>>59893170
you can do 256 characters with a byte for size
>>
>>59893170
> a single byte
Artificial restriction, I would have used Pascal-style strings with the first two bytes storing the length of the string. To be future-proof I would have added two macros, something like STR_LEN and STR_START, so I could've switched to 4-bytes lengths in the future when 32bit systems would've arrived.
>>
>>59893210
That is almost true (you can do 255 because size 0 has to represent empty string for tons of practical reasons). How is this relevant? It's clearly not enough. For 2bytes we could start to argue that you probably don't exceed that regularly.
>>
I'm in CS for the memes, and I suck at Python programming. I failed my second intro course, Python algorithms. Planning to retake it.

Trying to self-learn more stuff with codecademy and stuff, but am I fucked? Should I switch out of CS?
>>
>>59893275
>65535 is enough characters for everybody
>Nobody will never use more than 4kb ram
>>
>>59893170
>total number of characters in ASCII table is 256
gee, I dunno, a byte?
>>
>>59893275
So you save 1 byte and lose known length
>>
>>59893327
how do you FAIL a course? genuinely can't relate at all. i get nervous when my average is below 90%
>>
>>59893340
He is talking about when C was written and people did have very little memory

Unlike you, who apparently still has very little memory
>>
>>59893359
i failed because i was too lazy to do the work. suck at programming so i did bad on assignments and exams
>>
>>59893375
you should try to find something you can be passionate about and do that, you're not gonna achieve anything of worth in the realm of csci if you don't care enough to do homework...
>>
New thread: >>59893436
>>
>>59893340
Not saying that.
I'm saying that just like C++ put a constraint by having the size be a size_t. Back then it's worth considering if 2 bytes is a worthwhile tradeoff. I didn't even say it's a good idea. It's not easy to figure out but they probably concluded it wasn't. You don't tend to flip a coin for these decisions.
>>59893349
One byte per string yes. It's a tradeoff made for more flexibility. If you absolutely need a known size rocking a pointer+size structure isn't hard. The null terminated string fit more cases back then.
It's a conscious and sensible tradeoff.
>>
>>59893423
that's the hard part, i can't find something i'm passionate about. i'm already in second year

i'm gonna try harder now but i still have no motivation
>>
>>59893347
There are 128 characters in ascii and that's not what his question was about.
>>
>>59893423
Not anon but I don't trust someone who doesn't object to the homework in the earlier years of CS studies. It's a mundane waste of time. If your motivation is getting a degree over reading about interesting shit then you're a good student but you're probably not gonna be the best person for any given job.
>>
>>59893492
it's mundane only if you already know the stuff
>>
I'm a total noob /g/.
I just have one question, should i learn Python or C++?
>>
>>59893744
No
>>
>>59893744
it's usually python first.
>>
>>59893492
if it's such a waste of his time why did he flunk the course? i reckon he wasted more of his time by not doing it
>>
>>59893776
i just have zero motivation, that's why i didn't do the work and flunked the course. got rekt on exams
>>
>>59893797
>zero motivation
this field is not for you
>>
>>59893797
if you're a freshman it might just be a phase. you might be depressed from moving out to college. i was kind of depressed and unmotivated freshman year but i didn't fail any classes b/c i'm to intelligent and the classes weren't very hard. if you think computer science and hacking and all that is cool it might just be a phase
>>
>>59893883
well shit what other field could be for me. it might as well just be depression that can be fixed by antidepressants i'm taking right now. i already switched from chemistry to CS. I wish I went into engineering.
>>
>>59893905
>i was kind of depressed and unmotivated freshman year
i didn't move out, i'm still living with my parents

freshman year i got 1.8, which put me on academic warning. then the third term i got 1.3 and did even worse. fourth term i had the chance to bring my GPA back up, but I got a psychosis and had to withdraw. Now I'm gonna be required to withdraw for a year from uni because of that 1.3 GPA
>>
>>59893797
>zero motivation
you're competing with people who will program for 24 hours straight just for the fun of it nigga

you don't really need work ethic if you don't consider what you're doing to be work
>>
New thread: >>59893949
>>
>>59893942
>you're competing with people who will program for 24 hours straight just for the fun of it nigga
shit that's true, CS has a lot of nerds for sure.

man i don't even know anymore, maybe i should just take a year off and get into wagecucking so i could feel better about uni

my grandpa pays my tuition and everything, i got nothing to actually worry about
>>
>>59893964
no really school just might not be your thing. my brother attempted suicide in college and dropped out when it didnt work and ive never seen him happier
>>
>>59893964
imo you should only go to uni if you really want to. you can still come back later if you change your mind about it. and you can try learning programming on your own as well.
>>
>>59894118
i'm definitely trying to learn programming on my own time while on my break. im doing a codecademy python course
>>
>>59888600
Why write this in C++?
Thread posts: 345
Thread images: 21


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.