[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 Pascal 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: 312
Thread images: 25

File: THIS-IS-PASCAL--meme-27527.jpg (27KB, 600x597px) Image search: [Google]
THIS-IS-PASCAL--meme-27527.jpg
27KB, 600x597px
What pascal/delphi projects are you working on /g/?

Last thread >>0
>>
File: Untitled.png (372KB, 1920x1080px) Image search: [Google]
Untitled.png
372KB, 1920x1080px
If someone guesses what im working on i will deposit 5 shekels into his account.
>>
>>62149024
last thing today was batch processing of some OLE for a lazy customer

>>62149041
string overflow in delphi ?
>>
File: dpt.jpg (285KB, 500x749px) Image search: [Google]
dpt.jpg
285KB, 500x749px
>>62149041
>▲
At last, a program that will let newfags triforce?!
>>
>>62149024
Last time i did pascal was Turbo Pascal in high school.
>>
File: 1502858880504.gif (460KB, 300x300px) Image search: [Google]
1502858880504.gif
460KB, 300x300px
>>62149024
Hello internet and welcome to behind the meme today we have a look at this is sparta thank you all for suggesting this meme you guys wanted it now you have it HERE WE GO
>>
>>62149396
im not usig ansistrings.
>>
>>62149416
VERY CLOSE
>>
>>62149809
What's the benefit of using ShortString over AnsiString?
>>
>>62149905
Memory/performance and better garbage collection.
>>
File: DPT.png (304KB, 588x390px) Image search: [Google]
DPT.png
304KB, 588x390px
>>62149905
Should technically be more efficient if you don't need > 256 character strings, no allocation/deallocation on the heap.

If you somehow had an interface that expected "Pascal" strings (it looked for the length in the first byte) then ansistring obviously wouldn't work, but I don't know if such a thing exists like interfaces that expect null-terminated strings do because of C.
>>
>>62150044
I see. And yes, I think I've struggled with that already, now that you say it
>>
File: resumen_corte.png (215KB, 1920x1080px) Image search: [Google]
resumen_corte.png
215KB, 1920x1080px
>>62149024
I'm currently working in a production system, still using Delphi 7 in Virtual Box with Windows XP.
>>
>>62150137
OP aquí.
Parece que los unicos que quedan usando Pascal/Delphi son españoles o rusos.

Delphi 7 hasta la muerte.
>>
>>62150137
Btw wich DB are you using. Last time I did a DB program it was SQlite. Firedac is super comfy.
>>
some customer asked me to display additional information in a 3rd party application.

I managed to draw a panel with my info in the window but haven't been able to bind it to a specific tab for example.
Is that even possible without DLL injection?

How do tools like WinSpy++ get a window's contents and manipulate their properties?
>>
>>62150496
as for the last question, I've found the source of it.
>>
>>62150226
I'm using Firebird SQL.
>>
https://pastebin.com/T1JB1W4y
>>
>Python
>Ruby
>Node
>Go
>Erlang
>>>/g/wdg
>>
>>62149024
Last time I used FreePascal was a game where you move a block and dodge other blocks and go through a maze.
>>62149041
a pascal's triangle creator?
>>
>>62151740
the only true functional programming language, unlike Haskell
>>
>>62151952
haskell is a truer functional programming language than racket
racket has objects and mutable variables and it does type checking at runtime via contracts which is pretty much the most dystopian possible situation as far as type systems go
>>
>>62151740
>#t))))))]) self))
Meh, I don't like Lisps.
>>
>>62151740
No helper functions, good luck getting me to read that.
Seems pretty neat tho, nice OOP implementation
>>
>>62152005
no. racket is full of macros. not functional.
>>
>>62152005
This.

Whenever people go on about Clojure specs or whatever runtime checking is currently popular, they completely miss the point.

I want to prove things about my code, not find out about them at runtime.
>>
/g/ toddlers don't know the difference between metaprogramming and functional programming
>>
>>62152064
/g/ autists think lisp isn't functional. it's the actual original functional language.
>>62152005
no they aren't functional at all. haskell is macro spam.
>>
>>62152005
>pretty much the most dystopian possible situation as far as type systems go
At least it offers ways to easily introduce comprehensive runtime checks, it is fairly strict about how objects can be used, and doesn't implicitly convert types. It's much less dystopian than e.g. Python or JS. But ofc it's not statically typed so you'll never have the same guarantees as other languages like OCaml
>>
>>62152086
>Lisp
>Functional
You have to be at least 18 to be posting here. Get out.
>>
>>62152089
Python is strongly typed.
>>
>>62152101
Congrats for Python. Python also has broken scope rules, can't decide if its OOP or not, and is entertaining the idea of a pathetic form of gradual typing
>>
>>62152101
No it's Duck typed. It doesn't do implicit type conversion but nor does it do any type checking. It just checks for attributes/methods you access at run time.
>>
how could borland/embarcadero do windows api better than microsoft themselves
>>
>>62152157
>Python also has broken scope rules
que?
>>
>>62152157
Don't forget that apparently Guido wants to remove lambdas from it.
>>
>>62152157
Don't forget CPython.
>>62152183
>Don't forget that apparently Guido wants to remove lambdas from it.
que?
>>
>>62152157
>Python also has broken scope rules
It doesn't.

>can't decide if its OOP or not,
Are you pretending that multiparadigm programming languages aren't a thing? It's not either--or.

>>62152163
It is strongly typed.

>>62152178
He thinks that since Python do function scoping (and not block scoping), that scoping is broken. He's just being retarded
>>
>>62152199
https://www.artima.com/weblogs/viewpost.jsp?thread=98196

>The fate of reduce() in Python 3000
>by Guido van van Rossum

>About 12 years ago, Python aquired lambda, reduce(), filter() and map(), courtesy of (I believe) a Lisp hacker who missed them and submitted working patches. But, despite of the PR value, I think these features should be cut from Python 3000.
>>
>>62152217
>function scoping
>scoping is broken
modus ponens
>>
File: IMG_0038.jpg (318KB, 1536x2048px) Image search: [Google]
IMG_0038.jpg
318KB, 1536x2048px
What Swift projects are you working on /g/?
>>
>>62152178
Pros of python scopes
>you don't have to press a few extra keys to define your variables

Cons of python scopes
>confusing behavior if you forget to type "global"
foo = 3
def incr_foo():
foo = foo + 1


>very hard to immediately tell if a variable is local or not
foo = 3
def example_1():
print(foo)

def example_2:
print(foo)
if True:
if False:
foo = 2


>confusing and broken rules for nested functions
def outer():
x = 3

def inner():
x = x + 1
# nope, impossible to mutate outer's x
return x

return inner
>>
>>62152233
Wow, that's about the first nice thing GVR does.
One shouldn't cater Lisp feggits out of principle.

>>62152217
>It doesn't.
Not him, but that is where you are wrong, kiddo. Full block scoping is the only scoping that should exist, even thinking deviant from that should be rewarded with a bullet.
>>
>>62152170
>>being so sore loser you literally have to samefag pretending to be two different posters
No dude. I'm the guy who originally posted that code and I'm also the guy who said Haskell is a truer functional programming language than Racket and listed things Racket has that aren't functional. I know Racket isn't true functional programming, I never wanted it to be, I was never drawn to it for that reason, and if I were, why the hell would I be trying to implement OOP in it, especially given that Racket already has OOP.
>>
>>62152269
>>62152266
>>62152252
>>62152217
>>62152178
More important, Python doesn't forbid variable usage without declaration.
>>
>>62152266
oh so it's not broken at all it's just like every other language without declarations
>>
File: IMG_0039.jpg (344KB, 1536x2048px) Image search: [Google]
IMG_0039.jpg
344KB, 1536x2048px
>>62152253
tapping on the flag opens this interface
>>
w-what the hell is happening with our pascal bread q.q
>>
>>62152303
>it's just like every other broken piece of shit scripting language
FTFY
>>
File: 1484707311198.webm (3MB, 1276x1048px) Image search: [Google]
1484707311198.webm
3MB, 1276x1048px
>>
>>62152317
variable declarations are hard anon
>>
>>62152303
I'm saying that languages that don't declare variables are bound to have really shitty behavior that could've been avoided by just making declarations explicit.
I consider this "broken" but I guess it's a matter of opinion

>>62152296
Yes. This makes it very annoying to refactor code, and makes all variable name typos runtime errors that could've been caught statically. "productive language" my ass
>>
>>62152315
>making money off of brazilians
good luck
>>
>>62152325
???
>>
>>62152100
prove lisp isn't functional.
>>
>>62152319
Fuck off
>>
File: 1484195149571.webm (3MB, 1476x872px) Image search: [Google]
1484195149571.webm
3MB, 1476x872px
>>
>>62152336
See >>62152325
>>
>>62152348
https://pastebin.com/Q80H5f8y
>>
>>62152296
>Python doesn't forbid variable usage without declaration.
It does, wtf?

>>62152269
>>62152252
>Full block scoping is the only scoping that should exist
Tell that to Haskell developers
>>
>>62152336
it's productive if your main goal is to write code quickly, regardless of how many bugs it has.
>>
>>62152319
I remember learning Delphi in school
>>
>>62152336
not really. after all a true functional language doesn't need variables.
>>
>>62152319
>using windows
>using an IDE
>the IDE takes 12 seconds to load
>there are non-english characters in the source code
>building and running it creates a virus shitware program that sits on your windows
>shitware-chan is literally not even cute she looks like she was drawn by a 3 year old
so this is the power of
of
of
... of
of--
what the fuck actually is this
>>
>>62152372
Haskell can get away with it because of immutability.
>>
>>62152319
holy shit anon, that's impressive. Any links?
>>
>>62152372
It doesn't forbid it statically. Racket, for instance, is interpreted, but completely forbids variable usage without declaration.

>Tell that to Haskell Developers
Haskell has proper scoping rules

>>62152377
I want to write code quickly, be able to change code quickly, and I want to identify bugs quickly because they're bound to happen.

>>62152384
That is correct
>>
File: 1483916193167.webm (3MB, 1612x892px) Image search: [Google]
1483916193167.webm
3MB, 1612x892px
>>
>>62152370
read it. isn't proof.
>>62152358
holy fuck you made that. tell me, is it FOSS? source pls
>>
>>62152336
>>62152317
I agree that it sucks but it's hardly unique to python.
>>
>>62152410
what language is that? looks like a dialect of python
>>
>>62152411
You are an embarrassment to the FOSS
>>
>>62152339
Since it's my native language, why not add that translation?
>>
>>62152410
Nice.
Github?
>>
>>62152411
>anything I don't like is not a proof
>>
>>62152433
That shit doesn't look anything like python.
>>
>>62152395
haskell doesn't have true immutable memory though. nothing beats Cs const specifier (actually marks memory as readonly)
>>
>>62152451
>>62152411
It's closed source, gullible children
>>
>>62152464
epic meme
>>
>>62152442
SOPA

>>62152433
Have you tried reading the thread title?
>>
>>62152433
>>62149024

you're in the wrong bread
>>
>>62152453
it does. but seriously what language is that?
>>
>>62152409
>It doesn't forbid it statically.
It does. You can literally not use a variable without it having been declared first.

>Haskell has proper scoping rules
It only has function scoping.
>>
>>62152372
>It does, wtf?
# no declaration
x = 1
if x == 2:
y = 1

# fails at runtime
print(y)

# boohoo, flow control was too hard to implement for GVR


>Hasklel
>aka the guys who couldn't even build a proper compiler for almost 20 years, much less a useful language
Why would I care for their opinions?
>>
File: dptsepia.png (2MB, 2500x1000px) Image search: [Google]
dptsepia.png
2MB, 2500x1000px
>>62152433
Delphi, a dialect of Object Pascal. Perhaps more similar to C# than Python, but the preference of words to symbols certainly makes it look more like Python than C-like languages.
>>
>>62152473
>>62152475


it's pascal/delphi?
>>
>>62152488
>>Haskell has proper scoping rules
>It only has function scoping.
But it doesn't cause the same problems in Haskell because Haskell values are immutable.
>>
C++ question time.

Here's what I want to do: Have a manager class, that takes a member function/method and the instance it belongs to, then calls that method on the correct instance at some point down the line.

However: C++ does not like it when you try to pass around methods as function points, for understandable reasons.

So what's the proper way to design this?

If that's unclear, think of my manager class as a publisher, and the instances as subscribers. I want to be able to subscribe to the publisher's messages, via a callback or something.
>>
>>62152480
DELPHI/PASCAL THREAD
IT'S FUCKING DELPHI
NOW GO AWAY
>>
>>62152488
>It only has function scoping.
This isn't true. Where did you get this idea?
>>
>>62152416
>I agree that it sucks but it's hardly unique to python.
True. Hilarious how Perl got this right, at least in strict mode everyone uses.
>>
>>62152409
>identify bugs quickly
That's what static typing is for.
>>
>>62152511
By knowing Haskell.
>>
>>62152491
Haskell isn't truly functional since it lacks the const specifier.
>>
>>62152506
pointer-to-members exist, you know
>>
>>62152506
C++ and POO were both mistakes.
>>
>>62152506
Stop posting other languages on this Pascal Thread. Read the title.
>>
>>62152506
wtf is this oop goop
>>
>>62152491
>fails at runtime
>fails
That is "forbidding variable use without declaration" are you literally retarded?
>>
>>62152506
hmmmmmmm
i would use the visitor design pattern with a hint of pattern matching.
>>
>>62152500
correct
>>
>>62152524
this is the kind of craziness that some people actually believe
>>
>>62152512
I'm actually not familiar with Perl, could you give me the rundown?
>>
>>62152541
its simple as fuck. OP is autistic,,
>>
>>62152541
Yeah, but they get some fucked up type like
MyClass::*

And casting that to void* is supposedly a bad idea (from what I've read).
>>
>>62152567
it's what happens when people talk about things that they don't understand
>>
>>62152554
>>62152524
>>62152464
>>62152348
Epic thread guys, you're doing good work
>>
>>62152253
Stop using the Pascal Thread to fill it with fagot languages.
>>
>>62152549
Hate to tell you, but it's only useful at compile time.
I bet you mongoloid are overly grateful that your shitty interpreter even catches binding errors instead of just crashing.
>>
>>62152506
What? Of course you can pass methods as function pointers.
bla(&class::function, class_ptr);
>>
>>62152607
Shouldn't have called it /dpt/ then
>>
>>62152501
>>62152395
>But it doesn't cause the same problems in Haskell because Haskell values are immutable.
No, it causes other kinds of problems instead, like generating 1 gigabyte of data per second that's immediately garbage collected.

>>62152611
>Hate to tell you, but it's only useful at compile time.
Python is an interpreted language, why are you pretending to be retarded?
>>
>>62152629
Go back to >>>>lgbt
>>
>>62152630
>No, it causes other kinds of problems instead, like generating 1 gigabyte of data per second that's immediately garbage collected.
I see that you have responded with an irrelevant meme in lieu of an argument.
>>
>>62152600
incorrect. even C has const. Java has const. Haskell? no const. therefore it has no true immutable memory. unlike for example FUCKING C++

#include <vector>
int main()
{
const std::vector<int> a;
a.clear(); // WONT COMPILE FFS
return 0;
}
>>
>>62152648
Haskell has const

example = const 3
>>
>>62152642
l2arrow

>>62152648
Java has final, not const.
>>
I'm having a problem with C#.
Is it possible to create a thread factory where whenever a method is accessed it spawns a new thread? I don't want huge overhead.
>>
>>62152673
You need the enterprise edition to do that.
>>
File: DPG.jpg (247KB, 934x1000px) Image search: [Google]
DPG.jpg
247KB, 934x1000px
>>62152607
Other languages are cool too, my latest project has been some little tools in C, but I'm working on some GUI parts with Free Pascal.
>>
>debating about haskell
>caring enough about haskell to argue one way or the other
>therefore being a hasklet even if you're on the side attacking it
>being a hasklet
>muh "moan ads"

>arguing about what languages are true functional programming
>believing functional programming is desirable
>literally being an fplet
>muh "lamb duhs"
>>
>>62152662
sorry, that's what I meant. I'm not a huge JVM programmer.
>>62152659
yea, but it isn't TRUE const. it's not fully immutable and you can't achieve referential transparency
>>
>>62152645
>irrelevant meme
Running out of memory is not a meme.
>>
>>62152707
i'd suggest Rust.
https://mmstick.gitbooks.io/rust-programming-phoronix-reader-how-to/content/chapter02.html
http://blog.madhukaraphatak.com/functional-programming-in-rust-part-1/
http://science.raphael.poss.name/rust-for-functional-programmers.html#id24

better performance, newer more crates, simple installation etc.
>>
>>62152695
where do i get it? im a beginner programmer, we started coding this year.
>>
>>62152568
It's a super retarded language designed by a guy with bibles in his panties. It gets a lot of things wrong, but amazingly, it has a better C embedding API than both CPython and MRuby and also can force the programmer to declare used variables in strict mode. That being said, having a strict mode is a sign of defeat in language design and Python definitively should have one.

>>62152630
>Python is an interpreted language, why are you pretending to be retarded?
Look retard, like almost every interpreter Python compiles its code to bytecode. And if you actually knew anything about interpreters you knew that you can perform that test even within the AST in a naive interpreter.
Let me now blow your dysfunct brain by telling you that you can also have static type checking in interpreters.
>>
>>62152673
You probably want tasks instead of threads.
>>
>>62152729
why would you suggest a functional language under any circumstances
>MUH "MOAN ADS"
>MUH "LAMB DUHS"
>MUH "MUTE ECKSES"
>MUH "SEE MUH FOURS"
>>
>>62152708
yes it is, look:

example = const 3

example 4 -- 3
example 5 -- still 3
>>
Which lang is worst lang and why is it sepples?
>>
>>62149024
I used pascal back in the 80s. Great for linked lists, not so good for low level file i/o. I didn't think anyone ever used it any more, at least outside of academia.
>>
>>62152779
it isn't, worst lang is trashkell
>>
>>62152779
>Which lang is worst lang and why is it sepples?
A tool is a tool. It depends on who uses it.
But if you want to cut a tree you better get an axe than a hammer.
That said rust is like using a dildo instead of an axe.
>>
>>62152782
>Great for linked lists
>linked lists
...Wait, in the 80 cache hierachies weren't that much of a thing so it's probably justified.
>>
>>62152708
$ cat a.c
#include <stdio.h>

int main(int argc, char **argv)
{
const int x = 3;
*((int*)&x) = 4;
printf("x = %d\n", x);
return 0;
}
$ gcc a.c -o a.out
$ ./a.out
x = 4


Immutable, is it?
>>
>>62152777
yeah still not true const though.
example = const 3
example const 4 : doesn't work

Lisp does it properly IMO
>>
>>62152819
That's undefined behaviour aka not C.
>>
>>62152782
Still better than C#.
>>
>>62152835
If it were invalid C then it would be rejected by the compiler.
>>
>>62152819
It is. C is the only lang. with full immutability..
What you did there was access and deference its ADDRESS as non const...
    *((const int*)&x) = 4;

doesnt work
>>
File: tomntoms.jpg (1MB, 1080x1080px) Image search: [Google]
tomntoms.jpg
1MB, 1080x1080px
why is this place so awful? it's the same fights in every thread
>>
>>62152819
not portable
undefined behavior
>>
>>62152825
you're using it wrong

example (const 4) -- still 3
>>
>>62152872
People doesnt read the title
>>
>>62152857
no. literally no. you're dumb as fuck. listen no matter how much you whine about
> MUH SEE
> MUH CONST
you will never achieve true const. Lisp has true const no other fake language has actual const.
const means placing memory in readonly sectors. if you can write to it its not const.
>>
>>62152857
incorrect
c as a language is defined by its specification not by what the compiler says
>>
>>62152864
But it changed the value of x. x was supposed to be truly immutable, to be in read-only memory! See >>62152464
>actually marks memory as readonly
>>
>>62152883
what? stop trying to shove the meme of Trashkell has const. It doesn't. It doesn't even have static const

example:
#include <stdio.h>

int main(int argc, char **argv)
{
const static const int x = 3;
*((const int*)&x) = 4;
printf("x = %d\n", x);
return 0;
}
>>
>>62152890
C has true const. You can't write to memory declared as const. It's not allowed.
>inb4 but i can, i did it durrrr
Not in C you didn't.
You did it in the superset of C defined by your compiler and runtime and their idiosyncrasies
>>
>>62152900
no! static const marks it as read only! but you can't cast it back to non const. that copies the memory back to RAM from the read only section. read the spec PLS!
>>
I hate programming
>>
>>62152890
We were talking about C, not Lisp.

>>62152940
If it is an invalid program then it should be rejected by a compiler.

If no C compiler exists that rejects such an invalid program, then it is a useless language, even more useless than Haskell.
>>
>>62152950
you should try Rust. the original function programming language according to autist anons
>>
>>62152872
Welcome to imageboards. Enjoy your stay.
>>
File: 1331972083325.jpg (233KB, 727x3382px) Image search: [Google]
1331972083325.jpg
233KB, 727x3382px
>>62152950
>I hate programming
you'd can't defeat me, i'm was the meme master
>>
>>62152973
incorrect. YOU USED UNDEFINED BEHAVIOUR
compile with -Wall -Werror and -Werror and IT WONT COMPILE!!!!!!!!
>>
>>62152973
>If it is an invalid program then it should be rejected by a compiler.
that's true
>If no C compiler exists that rejects such an invalid program, then it is a useless language, even more useless than Haskell.
this however isn't
>>
>>62152835
Undefined behavior is valid C though, most real world C code relies on implementation-specific behavior.
>>
>>62152940
i did you. C has true fake const.. Lisp has true const. if a language has const then its functional..
>>
Is Delphi worth learning over C# ?
>>
>>62153003
$ cat a.c
#include <stdio.h>

int main(int argc, char **argv)
{
const int x = 3;
*((int*)&x) = 4;
printf("x = %d\n", x);
return 0;
}
$ gcc -Wall -Werror -o a.out a.c
$ ./a.out
x = 4
>>
NEW TOPIC

All the ways in which C is superior to Trashkell / Delshiti / Pasdumb / Rust (self explanatory)
>>
>>62153026
Ok no first of all C's const is true const. Not true fake const, true const. Any program that can write to a const address is not C.
SECOND OF ALL:
functional programming is worthless
see: >>62152707 >>62152772
>>
>>62153043
try -Wextra
>>
>>62153044
>(self explanatory)
that's a stupid topic
enumerating things which are supposedly self explanatory is an exercise in redundancy and futility in the general case
>>
>>62153021
Implementation-specific behaviour is not the same thing as UB.
>>
>>62153048
That's true C's const is the only valid const. anyone who claims it's fake is a moron.
>>62153043
you're using it wrong. you are copying the memory from const into non const memory.

C has const. readonly memory. end of story.
>>
>>62153061
Rust is self explanatory because its name is mentioning that it is rusting ie garbage. we dont need to use onomatopeea like Delshiti to indicate its garbage
>>
>>62152819
That's undefined behaviour, you dumb fuck.
>>
>>62152857
The standard defines C, not the compiler. Also, if you enable strict compilation, that will not compile.
>>
>>62153081
(you)
>>
>>62153043
Compile with pedantic.
>>
>>62153112
(he)
>>
C const isn't real const
int main()
{
static const int x = 10;
int arr[x]; // vla
}

c++ const is true const
>>
>>62153100
C has const. C++ has final. Java has inheritance. what does Haskell have. A broken compiler
>>
>>62153043
>>62152917
#include <stdio.h>

int main(int argc, char **argv)
{
register const int x = 3;
*((const int*)&x) = 4;
printf("x = %d\n", x);
return 0;
}

$ gcc test.c 
test.c: In function ‘main’:
test.c:6:5: error: address of register variable ‘x’ requested
*((const int*)&x) = 4;
^
>>
>>62153118
no C const is real const.. C++ const in wrapper around final. learn C then talk. it's why Lisp, which is a func lang,, uses C for its compiler unlike C++ which cant do full const thus it cant do func prog
>>
>>62153122
>C has const. C++ has const. Java has final. what does Haskell have. literally no need for any such thing because everything is immutable always
ftfy
>>
File: 1499049100978.jpg (31KB, 252x496px) Image search: [Google]
1499049100978.jpg
31KB, 252x496px
>>62152319
/g/ was a mistake
>>
>>62153056
>>62153114
$ cat a.c
#include <stdio.h>

int main(void)
{
const int x = 3;
*((int*)&x) = 4;
printf("x = %d\n", x);
return 0;
}
$ gcc -Wall -Werror -Wextra -pedantic -o a.out a.c
$ ./a.out
x = 4


>>62153081
Haskell has read-only memory, if you look at the disassembled output:

$ cat a.hs
msg = "Hello, world!"

main :: IO ()
main = putStrLn msg
$ ghc -S -O3 a.hs
$ sed -n 17,34p a.s
.section .rodata
.align 8
.align 1
c3lO_str:
.byte 72
.byte 101
.byte 108
.byte 108
.byte 111
.byte 44
.byte 32
.byte 119
.byte 111
.byte 114
.byte 108
.byte 100
.byte 33
.byte 0
>>
Why should I use anything other than C# ever?
>>
>>62153135
finally someone who knows C. this is real const. this is what Lisps compiler uses under the hood for true func prog
>>
>>62153145
>C++ const in wrapper around final.
wrong, C++ const is C const
final is completely different and only applies to member functions
>it's why Lisp, which is a func lang,, uses C for its compiler unlike C++ which cant do full const thus it cant do func prog
wrong
const is a way of taking away undesired capability from a variable
when you're writing a language on the other hand you can take away any capability you want regardless of whether doing so is possible in the host language
>>
>>62153041
If you don't work for Microsoft yes. If you work for Microsoft stick to C#
>>
>>62153158
.rodata isn't readonly..
it's just data but it's not in readonly mem..
please understand this before you spit bullshit on internet boards.
>>
>>62153169
>>62153135
>C has to prevent you taking the address of a variable in order to prevent you from changing it
wow, great language guys, I'm convinced

>>62153190
You can use final as a class modifier, a member modifier, and a variable modifier
>>
>>62153190
no C++ const isnt readonly dude. C const is.

do you understand what readonly is. IT MEANS YOU CANNOT WRITE TO IT EVER.
>>
File: 1503970564218.gif (197KB, 462x326px) Image search: [Google]
1503970564218.gif
197KB, 462x326px
>>62152319
>>
>>62153206
>You can use final as a class modifier, a member modifier, and a variable modifier
nope only in java
in C++ it's only for member functions and classes
>>
>>62153158
You're manipulating the output. It produces a compiler error on my machine. Nice trolling though, 6/10 because you got me to actually try.

Also if you want proof that's UB replace const int with const char and assign it a string literal and then try to modify it.
>>
>>62153206
no you can't fuck off.
final List = new ArrayList<>();
>>
>>62153081
>you're using it wrong. you are copying the memory from const into non const memory.

I don't think you kids know what you're talking about.

A const in C is compile-time only. The only exceptions are floating point literals and string literals. A variable on the stack, that you use its address no less, will never be put on read-only memory. Globals may be read-only too, but that's unreliable behavior.

So no, he doesn't copy the memory "from const into non-const". The memory was never const to begin with.
>>
>>62153219
> MUH C
> MUH BUFFER OVERFLOW
> MUH ERROR
> MUH CRASHES
> MUH HACKERMANS MEMES
listen moron don't use C. it's outdated and doesn't even collect garbage.
>>
>>62153213
>no C++ const isnt readonly dude. C const is.
not what the conversation is about. C const is not necessarily readonly; that's a implementation detail and not part of the language specification. C++ const, implementation details aside, is C const. And they are both TRUE const, and this has NOTHING to do with implementation details or "readonly" which was not even a term involved in this discussion between the two of us up until now.
>do you understand what readonly is. IT MEANS YOU CANNOT WRITE TO IT EVER.
Do you understand what const is?
It means you cannot write to it within the scope of guaranteed well defined behavior.
It has nothing to do with "readonly" or other such implementation details.
>>
>>62153233
it was you fucking moron const can use register keyword to make it TRUE const...
compilers will optimize and take away const for performance... const is slower since its readonly by default..

do register const and its TRULY const.. not in RAM ata ll
>>
>>62153244
Damage control, much? Calm the fuck down
>>
>>62153246
you don't understand what const is. end of story.

> cppreference
>Objects declared with const-qualified types may be placed in read-only memory by the compiler, and if the address of a const object is never taken in a program, it may not be stored at all.

READ ONLY MEMORY
>>
>>62153201
It better be readonly because that's where the "const" data in C goes:

$ cat b.c
#include <stdio.h>

int main(int argc, char **argv)
{
register const char *x = "foo";
printf("x = %s\n", x);
return 0;
}

$ gcc -S b.c
$ head -4 b.s
.file "b.c"
.section .rodata
.LC0:
.string "foo"


If it's not readonly then C doesn't have "true const".
>>
>>62153201
.rodata is put in read-only memory by the process loader. There's no reason not to. That's what this field is for!
>>
>>62153268
Const without the register keyword is already true const because you have no way of knowing the data to which you have a reference or address isn't stored in read-only memory. It's not guaranteed to be stored in read-only memory, but that is literally not important whatsoever and anyone who wants a guarantee like that is working at too low a level. It's guaranteed NOT to be guaranteed NOT to be stored in read-only memory, which is what makes it true const--because if you try to modify it, it becomes mathematically impossible to prove the behavior of the resulting program is correct.
>>
>>62153288
yes but C has FULL readonly... see the .LC0
i think it refers to the CPU memory location or whatever..
i think for x86 its the readonly boundary (can only be written to at factory manufacturing) will check brb
>>
>>62153219
Or really? What's the error then?
>>
>>62153292
you don't understand

readonly data is somehow summoned into memory from nowhere when you run the program

>>62153299
>being able to trust that data that needs to be readonly for correctness won't be modified is not important
wew
>>
>>62153284
>READ ONLY MEMORY
Yes. That sentence sure did include the expression "read-only memory." Nice reading comprehension skills.
However, you seem to have made the mistake of deciding that const therefore MEANS read-only memory.
It doesn't.
Read more closely.
It means it MAY be read-only memory.
The "MAY" is the important thing here, and if something MAY be read-only at the hardware level, then it IS true const, regardless of whether or not it actually IS read-only at the hardware level. If you disagree, you are a bad programmer and don't write safe software.
>>
>>62153299
i don't know C, but i thought you needed 'register' to add a little extra bit of const sauce to the mix?
>>
>>62153328
THATS WHY YOU ADD REGISTER.. TO FORCE THE COMPILER TO ADD READONLY ALWAYS..

sometimes the compiler wont do it automatically for perf reasons i told you...
>>
>>62153315
>yes but C has FULL readonly... see the .LC0
>i think it refers to the CPU memory location or whatever..
>i think for x86 its the readonly boundary (can only be written to at factory manufacturing) will check brb
No. It's just a label.
>>
>>62153268
register is a placebo, kid. Get over it.
>>
>>62153334
>i don't know C, but let me spew some bullshit about it
I'm not picking on you in particular anon, but many people in this thread clearly have no clue about C.
>>
>>62153358
In the past it made a difference.
>>
Any opinions on Go? I wanted to try it but anons are telling me it's worse than Haskell
>>
>>62153327
>>being able to trust that data that needs to be readonly for correctness won't be modified is not important
Quite. It's not important and here's why.
First of all, data never needs to be readonly for correctness. Not in a hardware sense. If it does, you should be programming in assembly.
Secondly, if what you MEAN is that data needs to NEVER BE MODIFIED for correctness, which I suspect you do, then mark it const. That way, if YOU modify that data, you can only be doing so intentionally, and anything that breaks is therefore your fault, not that of the language, because you wanted it to break. If someone ELSE modifies the language, the same logic applies, so when your program breaks because of something THEY modified knowing it shouldn't be modified, it's THEIR fault, and by extent neither that of the language nor yours.
>>
>>62153292
Wut? Did you even think before you typed that response, anon?
>>
>>62153377
i mean i said i don't know C.
still C is objectively inferior to C++. no generics makes it garbage IMO.
>>62153383
Go is garbage since no generics.
>>
>>62153350
>FORCE THE COMPILER TO ADD READONLY ALWAYS..
This is not a desirable thing to do.
The fact that it MAY be in read-only memory is objectively enough.
If it's not enough for you, you're a bad programmer.
>>
>>62153390
You fucking dumb autist.
mprotect(buffer, pagesize * multiplier, PROT_READ);
makes memory readonly. writing to it causes segfault by the kernel.

anons who dont know C should GTFO
>>
>>62153324
error: pointer-type discards ‘const’ qualifier from pointer target type
>>
>>62153390
It must be nice not to consider malicious actors.
>>
>>62153407
>still C is objectively inferior to C++. no generics makes it garbage IMO.
C's one good feature over C++ is that you can write far worse code in C++ than you can in C.
>>
>>62153468
no you can't. just cause you don't understand it doesn't mean it's worse code.
write me a URL parses during compile time. C++ can do it C can't.

https://github.com/rep-movsd/see-phit

compile time HTML parsing in C++.
do it in C.
>>
>>62153492
C++ is a wholly excessive abomination of a language. there's no reason to use C++. period. so stop. get your life on track. use C.
>>
>>62153381
It still does, ref the discussion on cache coherent memory we had in one of the dpts yesterday.
>>
>>62153445
Error, not warning, with direct cast?! What compiler are you using?
>>
>>62153413
>you should just only use perfect third party libs regardless of what the client demands, instead of having safeguards
>>
>>62153492
>compile time HTML parsing
Not the other anon, but why would you want this?
>>
>>62153505
what's a dpt? i'm quite new
>>
>>62153407
C11 has _Generic
>>
>>62153519
a terrible place for terrible people
>>
>>62153515
you wouldn't. it just shows the power of C++.
you can use it effectively other places.
>>
>>62153445
Oh, I see, you're using -Werror... By default, that's a warning though.
>>
>>62153437
First of all: not portable.
If you need to do this for security reasons be my guest but it's not standard C.
Security SHOULD be platform dependent anyway.
Secondly that has nothing to do with the point I'm making. I'm not saying C has no facility for guaranteeing something goes in read only memory. I'm saying it's not a desirable or necessary feature for a non-assembly language to have, and it's beside the point of const.
>>62153446
see above
>>
>>62153492
I know you can write a compile-time URL parser in C++. That is irrelevant to whether you can write worse code in C++ than you can in C.

Additionally, you can also write far better code in C++ than you can in C.
>>
>>62153534
>sepples is good at things that have zero practicality
makes sense.
>>
>>62153542
Yes. But it's UB no matter what though.
>>
>>62153519
Daily programming thread.
>>
>>62153544
Compilers should refuse to target deficient platforms
>>
>>62153598
First of all that's not really related to what I just said.
Secondly no they shouldn't because then they wouldn't be implementations of the standard.
>inb4 the standard should change to exclude deficient platforms
No it shouldn't because security and other such concerns belong in an operating system not in a language.
>>
>>62153653
>First of all that's not really related to what I just said.
Yes it is.
>No it shouldn't because security and other such concerns belong in an operating system not in a language.
Security needs to be considered at every level.
>>
>>62153653
no. how long have you been writing C? you'd understand that deficient platforms are holding everything back, if you had been writing C for more than 1 year.
>>
>>62153708
x86 plus is-ought fallacy equals tragedy
>>
>>62153705
Moving goalposts.
Get the Fuck Out.
BTFO /pol/tard
>>
>>62153752
no
>>
>>62153749
what? fallacy fallacy.
>>
Who here excited for /Rust 2/
>>
File: tfwbrainlet.png (25KB, 837x391px) Image search: [Google]
tfwbrainlet.png
25KB, 837x391px
I need some advice on creating program that requires pic related
I will show my work
>>
File: program so far.png (33KB, 481x537px) Image search: [Google]
program so far.png
33KB, 481x537px
>>62153874
So here is what I have.
I have not been able to use the printColor function to print out the colors typed, or reversed the list
I also need to create a limit of the amount of colors but I have not been able to
>>
>>62153827
If you're here, a .gch file is a precompiled header file. You get them when you try to compile header files. They can be useful for speeding up compilation sometimes, by letting the compiler link in the compiled code instead of doing text substitution and having more code to compile, but most of the time--and especially for beginners--they're more trouble than they're worth, due to their potential to create confusing problems like the one you just ran into.
>>
>>62153888
Here's one problem:
cout<<i;

You're outputting the index of the color instead of the color itself.
Is nuAmount what stores the colors themselves?
If so, you want:
cout<<nuAmount[i];

Another problem is that if nuAmount *is* what stores the colors themselves, you're never actually populating it. Here's a snippet from your fillColor:
for (int i = 0; i < amount; i++){
cout<<"enter a color name: ";
cin>>color;}

You're populating the color variable with input, but you're not doing anything with the result. Every time you read in a string it's just overwriting the lsat string that was read in and nothing is ever actually going into the vector.
Here's what you want:
for (int i = 0; i < amount; i++){
cout<<"enter a color name: ";
cin>>color;
nuAmount.push_back(color);}

The vector member function "push_back" appends an element to the end of the vector.
>>
>>62153888
reverse order can be achieved by setting the starting index of the for loop to "size" and decrementing (i >= 0; i--).
>>
>>62153888
i'd suggest you use Haskell. since it has immutable types its the perfect cross platform functional programming language.
>>
Is there a clever way to organize architecture-specific code without resorting to #define hacks?
For example there are FooX86 and FooX64 that inherit from an abstract class Foo, but I want to be able to use a unified interface. Is unique_ptr downcasting the way to go?
>>
>>62154003
Thank you that fixed one of my problems
>>62154063
I'm not sure If I understand which for loop are you talking about?
>>
>>62154194
the one in printColor.
>>
>>62154165
what language? if C++, and you have C++14 availabe, use constexpr. much cleaner

like this

inline void Foo()
{
if constexpr(CHECK_MACRO_FOR_ARCH)
{
FooX86();
}
if constexpr(CHECK_FOR_X64)
{
FooX64();
}
}

// then in code you do

int main()
{
Foo();
}

>>
>>62154212
So you want
for (size(unsigned i >= 0; i<size; i--)){
cout<<nuAmount[i]<<"\n";}}
>>
>>62154276
for (int i = size - 1; i >= 0; i--) cout << nuAmount[i] << "\n";
>>
>>62154317
>>62154003
>>62154099
Thank you so much anons
>>
File: storage_picker.png (220KB, 680x673px) Image search: [Google]
storage_picker.png
220KB, 680x673px
I'm a total noob at android development.

I've been using tutorials to get the basics down, and think I know enough to start venturing into making my own shit. But where do I go from here? I'd like to start by trying to make a basic simple app.

What I'm thinking is an activity that hooks into the file selector, so you can choose it from the sidebar (under gallery, SD card, Dropbox etc. see pic related), called i.e. ImageSearch, and brings up a little window that lets you search google for an image to drop into your app.

I found this:
https://developer.android.com/guide/topics/providers/document-provider.html

As a starting point but where do I learn more about how to go about this? Any ideas for a beginner?
>>
Should I be drawing on a texture for OpenGL?
>>
File: cool clock.jpg (35KB, 599x347px) Image search: [Google]
cool clock.jpg
35KB, 599x347px
Is this bad practice?
int foo = argv[2];
//ishiggydoo
>>
File: moon robot.jpg (19KB, 210x240px) Image search: [Google]
moon robot.jpg
19KB, 210x240px
>>62154492
whoops sorry, meant to post it like this
int bar = atoi(argv[2]);
//ishiggittydigeridoo
>>
>>62154502
seems reasonable enough if you don't want to use argument parsing libraries.

you could use strtol and add some error checking
>>
Answer me this:

I have five applications of my own writing on a single box. How do I let them know about each other, without pre-programming their listening ports?
>>
>>62154597
dependent types
>>
Is it possible to write an android application without using a gigantic overbearing IDE?
>>
For a wiki URL naming scheme:
http://www.wiki.com/namespaces/MyNamespace/pages/YourMom

vs
http://www.wiki.com/pages/MyNamespace:YourMom


?
First one is more RESTy but it gives me aids.
>>
File: program modified.png (36KB, 483x523px) Image search: [Google]
program modified.png
36KB, 483x523px
>>62153888
The only problem I have left is to make amount less than or equal to 1000
>>
File: .png (10KB, 685x448px) Image search: [Google]
.png
10KB, 685x448px
This hangs randomly for some reason.
How do I debug it?
The threads make a few web requests but even when I put a timout on them, it stays frozen.
Not sure what's going on.
>>
>>62154656
No. Try again.
>>
>>62154716
kys
>>
>>62154716
>python
>multithreading
found your problem
>>
>>62154678
http://www.wiki.com?firstSlash=namespaces&secondSlash=MyNameSpace&thirdSlash=pages&thirdSlash=YourMom
>>
do you think it's better practice to generally try to define arrays in main and fill them in a function, or to use functions to create them on the heap and return a pointer? in C ofc
>>
>>62154725
dynamic types
>>
>>62154791
Ten kittens died after reading this post. I hope you're happy.
>>
>>62154851
Your functions should be affecting the state of a pointer you pass in, this way you can choose how your objects are allocated, instead of being forced to use the heap by design.
>>
>>62154165
>Is there a clever way to organize architecture-specific code without resorting to #define hacks?

https://en.wikipedia.org/wiki/Modular_programming

FooX86.cpp // implement Foo.H for x86
FooX64.cpp // implement Foo.h for x64
>>
>>62154930
that's the way i've been doing it. in what situation would it be preferable to use the heap?
>>
>>62149024
I hate the word procedure, so I'll just write in C
>>
>>62154915
Dumb
>>
>>62150137
one on hand: what the fuck
one the other hand: that zenburn scheme for whatever this is is fucking dope
>>
>>62153043
>-o a.out
>>
>>62153888
cant you just iterate backwards
>>
What c++ library would you recommend for handling xlsx or ods files (one of them will suffice)?
I want to create a scheduling script which would load data from a xlsx table and write it to another one.
>>
>>62150188
Y la facultad de ingenería en Montevideo en Programación 1 (Pascal)
>>
>>62154424
Bump for this:

https://www.youtube.com/watch?list=PLWz5rJ2EKKc-lJo_RGGXL2Psr8vVCTWjM&v=LaMUvV-gOfE

Looks to me like this is pretty complicated. Too much for a newfag?
>>
main = delete "/dpt/"
>>
>>62155118
That's weird, where I work the word "procedure" is used for basically any kind of task, even unrelated to programming, I can't imagine disliking it. And it's a mainly C/C++ place built on UNIX.

Or do you mean you just hate the verbosity, as in if C used "function" you'd hate that too?
>>
>>62155118
>implying functions don't exist in Pascal / Delphi.

Pascal / Delphi is super comfy. You know when a function MUST return a value because it's a function, if it doesn't return a value it's a procedure.
>>
>>62150188
In Brazil it was widely used too.
>>
So I have a list of nouns represented with an array of character arrays, and I'm trying to pass a character array to a function to return the position of where the characters end (i.e where the null-terminator is), so that I can add either an "s" or an "es" to the end of the noun to make it plural. But for some reason, it keeps crashing and I can't for the life of me figure it out.

int get_position_of_last_character(char* word)
{
int i = 0;
for (i = 0; i < 50; i++) {
if (word[i] == '\0')
break;
}
return i - 1;
}

int main()
{
//set PRNG seed
srand(time(0));

//print a noun
char* noun = nouns[RAND_NUMBER_RANGE(0, num_nouns)];

//decide whether or not to make it plural
if (RAND_NUMBER_RANGE(0, 2) == 1) {
//find out whether we need to add "s" or "es" to the end
int foo = get_position_of_last_character(noun);

if (noun[foo] == 's')
noun[++foo] = 'e';
noun[++foo] = 's';
noun[++foo] = '\0';
}
printf("%s ", noun);

return 0;
}


Could anyone tell me what I'm doing wrong?
>>
I hate when you can't think of clean algorithm to replace manually checking each case in a big old chain of if-else.
>>
>>62156196
I didn't knew that. Good to see that people are still learning and using it.
>>
>>62156233
This.
I started a thread 2 days ago to see if there is a better way to do this. I didn't found anything.
I wanted to do some kind of switch case but with strings.
>>
>>62156293
Yeah I find it stupid as hell you can't do switch on strings or anything other than ints since it all just boils down to branching once the code actually compiles
>>
>>62156217
    for (i = 0; i < 50; i++) {
if (word[i] == '\0')
break;
}

Why aren't you just getting the length of the string with strlen? This will most likely segfault on any string less than 50 characters and plain won't work on anything more than 50 characters.
>>
>>62156352
Why would a segfault occur if I'm reserving 50 bytes for each array?

Also I don't wanna deal with the bloat that comes with string.h
>>
>>62156293
>>62156337

what language ? in Java and C# strings work as you would think for cases instead of ints.
>>
>>62150188
algunos colegios tecnicos en BsAs todavia lo usan
>>
>>62156372
Provide more information then, where exactly is your program segfaulting?

>I don't wanna deal with the bloat that comes with string.h
This is retarded and you can easily just roll your own strlen anyway
>>
>>62156404
Huh I forgot it worked in Java. I guess only C/C++ are at fault. This is one thing I have to give to the "C must fall"fags
>>
>>62156424
>Provide more information then, where exactly is your program segfaulting?
I don't know, it just crashes whenever the helper function is called.

>you can easily just roll your own strlen anyway
What I'm trying to do.
>>
>>62156440
Run it through valgrind.
>>
>>62156440
How is nouns declared?
I'm guessing you're trying to write stuff to constant strings, and that's causing your crash.
>>
>>62156521
He insists it's crashing in the "get_position_of_last_character" function though
>>
>>62156440
>hardcoding a character limit in your strlen
it's a pretty shitty strlen to be honest with you
>>
>>62156565
I'm not gonna need more than 50 characters for any of them, so

>>62156521
theyre declared like
char *nouns[] = {"Faggot"};
>>
>>62156631
>I'm not gonna need more than 50 characters for any of them
for now
you're not getting any better performance and all you're doing is making changing your program in the future more difficult
>>
>>62156645
Name a word that has more than 50 characters
>>
>>62156631
Yeah, that's the problem.
"Faggots" in its current state can't be edited, because of how it's initialized. You need to copy it to another buffer instead of just pointing to it.

e.g. something like

char noun[64];
strcpy(noun, nouns[RAND_NUMBER_RANGE(0, num_nouns)]);
// etc
>>
new thread: >>62156754
Thread posts: 312
Thread images: 25


[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.