Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

sepples

Name: Anonymous 2009-01-19 18:16

Hey /prog/
I never really used C or C++ before, other than when I started learning programming. I want to do something in one of them, (maybe an OS lol) but I'm not very confident about allocating/freeing up memory (I haven't done it before often).
Just to refresh my memory, as long as I use malloc and free with C and new and delete keywords with C++ I'm safe, right? And can I use malloc and free in C++ too?

Also, discuss Objective-C and the Sepplesox I heard about before.

Name: Anonymous 2009-01-19 18:17

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Name: Anonymous 2009-01-19 18:20

You want to write an OS, and you can't do simple memory management?

Name: Anonymous 2009-01-19 18:20

Yeah pretty much, just remember to free things in a timely manner and make sure that your pointers are always pointing to something that's yours when you dereference them.

Name: Anonymous 2009-01-19 18:21

>>3
Notice the lol after that?

Name: Anonymous 2009-01-19 18:22

malloc and free can be used in both C++ and C, but new and delete are only for C++. If you're working with objects, you need to use new/delete so that constructors and destructors are called. Just be sure you don't delete a malloc'd region, and vice versa for free/new.

C++0x is the next revision of the C++ standard. The standard will include "C++ Technical Report 1 (TR1)", which is a set of class additions to the library. Additionally, the standard aims to improve multithreading support and adds some weird operator (&&), which you'll most likely never use.

Objective-C is weird

Name: Anonymous 2009-01-19 18:23

>>4
>and make sure that your pointers are always pointing to something that's yours when you dereference them
Can you elaborate a bit? Do you mean NULL-ing them after dereferencing?

Name: Anonymous 2009-01-19 18:26

>>7
forgot my space

>>6
If you're working with objects, you need to use new/delete so that constructors and destructors are called.
I know that already, but thanks.

Was Objective-C the wierd thing with BEGIN_PUBLIC_MEMBERS or whatever those macros were?

Name: Anonymous 2009-01-19 18:27

>>8
Haha, yeah man that sucks. Come check out my pics at
http://www.flickr.com/photos/22931539@N05/

Name: Anonymous 2009-01-19 18:27

>>7
Yeah, that's part of it.  But generally just stop whenever you dereference a pointer and confirm that it's pointing to an active block of memory which you are allowed to play with and nowhere could the pointer have ever been overwritten with junk data.  That saves probably half the time spent debugging C programs.

Name: Anonymous 2009-01-19 18:27

>>6
Objective-C is weird
Lol wat. Objective C is just C mixed with Smalltalk.

Name: Anonymous 2009-01-19 18:29

>>11
Would you consider bash mixed with Haskell weird?

Name: Anonymous 2009-01-19 18:29

>>12
Haha, yeah man that sucks. Come check out my pics at
http://www.flickr.com/photos/22931539@N05/

Name: Anonymous 2009-01-19 18:31

>>12
Yes, because it would be stupid. Objective-C brings stuff that C sorely needs/damages Smalltalk enough to be acceptable to Ctards.

Name: Anonymous 2009-01-19 18:31

>>13
/prog/ is becoming youtube

Name: Anonymous 2009-01-19 18:40

Also, how's string support in C++? And can you point me to some good learning resources? I heard of something called K+R.

Name: Anonymous 2009-01-19 18:41

>>16
It has C strings, which are a pointer to a memory location and hopefully a NUL terminator somewhere. Then it has a string class. Then every library implements its own string class. Lol. IOW, shitty.

Name: Anonymous 2009-01-19 18:44

>>14
Not really. Ctards, by definition, only accept C as their personal lord and saviour. He who embraces Objective-C is probably a crossbreed between a Smalltalker and performance nut.

Name: Anonymous 2009-01-19 18:47

How do I make sure a char* has a 0 somewhere? Should I zero all the elements (I vaguely remember there being a function for doing that), or manually put a zero at the end/at the start?

Name: Anonymous 2009-01-19 18:51

>>19
0/10

Name: Anonymous 2009-01-19 18:53

you only really have to worry about null terminators if you're manually fucking with the string as an array.

Name: Anonymous 2009-01-19 18:54

>>15
Get ready to shit bricks
/prog/ was always youtube

Name: Anonymous 2009-01-19 18:55

>>19
Long answer: Any time you use a string literal (a string in double quotes) you get a NUL at the end. So make sure you've got enough memory to fit all the characters and the terminator. Likewise, string handling functions will return a properly terminated string unless otherwise noted. If you're creating a string from characters or something yourself, you can do what you like. Putting a NUL at the end will be fine, or you could zero your buffer first.

Short answer: if you write string handling in C I'm going to hunt you down.

>>18
Yes, really. Ctards is a blanked term for people who like C-family languages, especially Sepples. C not quite as much, although an obsession with PARFORMANCE is Ctarded. Objective-C and languages like D are also included, although to a lesser degree. The essence of Ctardation is sticking with C-family languages even though everything is better. I know, because I invented the term.

Name: Anonymous 2009-01-19 19:02

WHY ARE YOU HELPING HIM‽

Name: Anonymous 2009-01-19 19:13

>>23
Any time you use a string literal (a string in double quotes) you get a NUL at the end.
That's what I thought.
you could zero your buffer first.
So can anybody tell me if there's a function to do this or if I should use a for loop (lol)?
if you write string handling in C I'm going to hunt you down.
Is it really that bad?

I'm going to sleep now, /prog/
Thanks for helping me, and I hope that you will have a nice day/night.

Name: Anonymous 2009-01-19 19:16

>>23
Motherfuckers invented Objective-C because an Smalltalk-based at the time system would be too goddamn slow to be profitable as an end-consumer product. They improved the lives of hundreds of programmers that would be otherwise stuck with using plain C. Don't you be dissing no Objective-C, nigger.

Name: Anonymous 2009-01-19 19:18

>>26
s/\(at the time\) \(system\)/\2 \1/

Name: Anonymous 2009-01-19 19:19

>>26
Because the choices at the time were Smalltalk or C, right? Ctarded tunnel-vision.

Name: Anonymous 2009-01-19 19:22

>>25
Is it really that bad?
Consider, you had to come here and ask questions about the format of a fundamental data type. And what you learned is that any function that operates on this type must keep that format in mind (so it can allocate buffers that are big enough), even if it makes use of other string-manipulation functions to do the dirty work. This is the most colossal failure of abstraction in any popular programming language.

Name: Anonymous 2009-01-19 19:23

>>26
They should've put their time into improving Smalltalk virtual machines instead, thereby saving us all a lot of trouble.

Name: Anonymous 2009-01-19 19:23

>>23
Wait, so if I do something like this:
  char lel[] = "wat";
I actually get

  ┌───┐  ┌───┐  ┌───┐  ┌────┐
  │ w │  │ a │  │ t │  │ \0 │
  └───┘  └───┘  └───┘  └────┘


in memory? And strlen(lel) == 3, despite the presence of the NUL terminator?

Name: Anonymous 2009-01-19 19:28

>>31
[code]............................................________
....................................,.-‘”...................``~.,
.............................,.-”...................................“-.,
.........................,/...............................................”:,
.....................,?......................................................\,
.................../...........................................................,}
................./......................................................,:`^`..}
.............../...................................................,:”........./
..............?.....__.........................................:`.........../
............./__.(.....“~-,_..............................,:`........../
.........../(_....”~,_........“~,_....................,:`........_/
..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}
...........((.....*~_.......”=-._......“;,,./`..../”............../
...,,,___.\`~,......“~.,....................`.....}............../
............(....`=-,,.......`........................(......;_,,-”
............/.`~,......`-...............................\....../\
.............\`~.*-,.....................................|,./.....\,__
,,_..........}.>-._\...................................|..............`=~-,
.....`=~-,_\_......`\,.................................\
...................`=~-,,.\,...............................\
................................`:,,...........................`\..............__
.....................................`=-,...................,%`>--==``
........................................_\..........._,-%.......`\
...................................,<`.._|_,-&``................`\[/code]

Name: Anonymous 2009-01-19 19:29

>>32 FUCK
............................................________
    ....................................,.-‘”...................``~.,
    .............................,.-”...................................“-.,
    .........................,/...............................................”:,
    .....................,?......................................................\,
    .................../...........................................................,}
    ................./......................................................,:`^`..}
    .............../...................................................,:”........./
    ..............?.....__.........................................:`.........../
    ............./__.(.....“~-,_..............................,:`........../
    .........../(_....”~,_........“~,_....................,:`........_/
    ..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}
    ...........((.....*~_.......”=-._......“;,,./`..../”............../
    ...,,,___.\`~,......“~.,....................`.....}............../
    ............(....`=-,,.......`........................(......;_,,-”
    ............/.`~,......`-...............................\....../\
    .............\`~.*-,.....................................|,./.....\,__
    ,,_..........}.>-._\...................................|..............`=~-,
    .....`=~-,_\_......`\,.................................\
    ...................`=~-,,.\,...............................\
    ................................`:,,...........................`\..............__
    .....................................`=-,...................,%`>--==``
    ........................................_\..........._,-%.......`\
    ...................................,<`.._|_,-&``................`\

Name: Anonymous 2009-01-19 19:31

What's with the C-hate in here? The language has a lot of uses for writting fast code, or just for more lower level jobs.

It may not be the best thing to for certain jobs, as you could use a more suitable language for performing higher level tasks, reducing the amount of code the programmer needs to write, as well as reducing errors he may have in his newly written code.

C has its uses, and so do other languages, it's your choice what's better for the job.

Name: Anonymous 2009-01-19 19:33

>>34
What's with the C-hate in here?
Because LISP is the master language.

Name: Anonymous 2009-01-19 19:33

>>33
                  ............................................________
    ....................................,.-‘”...................``~.,
    .............................,.-”...................................“-.,
         .........................,/...............................................”:,
    .....................,?......................................................\,
       .................../....
.......................................................,}
    ................./......................................................,:`^`..}
    .............../...................................................,:”........./
    ..............?.....__.........................................:`.........../
                  ............./__.(.....“~-,_..............................,:`........../
    .........../(_....”~,_........“~,_....................,:`........_/
    ..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}
                  ...........((.....*~_.......”=-._......“;,,./`..../”............../
    ...,,,___.\`~,......“~.,....................`.....}............../
               ............(....`=-,,.......`........................(......;_,,-”
    ............/.`~,......`-...............................\....../\
    .............\`~.*-,.....................................|,./.....\,__
    ,,_..........}.>-._\...................................|..............`=~-,
    .....`=~-,_\_......`\,.................................\
            ...................`=~-,,.\,...............................\
    ................................`:,,...........................`\..............__
             .....................................`=-,...................,%`>--==``
    ........................................_\..........._,-%.......`\
    .............................
......,<`.._|_,-&``................`\

Name: Anonymous 2009-01-19 19:35

[m][sub]............................................________
....................................,.-‘”...................``~.,
.............................,.-”...................................“-.,
.........................,/...............................................”:,
.....................,?......................................................\,
.................../...........................................................,}
................./......................................................,:`^`..}
.............../...................................................,:”........./
..............?.....__.........................................:`.........../
............./__.(.....“~-,_..............................,:`........../
.........../(_....”~,_........“~,_....................,:`........_/
..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}
...........((.....*~_.......”=-._......“;,,./`..../”............../
...,,,___.\`~,......“~.,....................`.....}............../
............(....`=-,,.......`........................(......;_,,-”
............/.`~,......`-...............................\....../\
.............\`~.*-,.....................................|,./.....\,__
,,_..........}.>-._\...................................|..............`=~-,
.....`=~-,_\_......`\,.................................\
...................`=~-,,.\,...............................\
................................`:,,...........................`\..............__
.....................................`=-,...................,%`>--==``
........................................_\..........._,-%.......`\
...................................,<`.._|_,-&``................`[/sub]
[/m]

Name: Anonymous 2009-01-19 19:43

>>31
How do you think strlen works? It simply iterates over the string while counting chracters, until it finds a null byte. It's called ASCIIZ. strlen returns the length of the actual string, not the amount of memory you need to store it. The amount of memory you need to store it is length+1( including the ending null, otherwise, if you don't include it, strlen would go on counting, and may as well count into other memory on the heap(or wherever you allocted your string) which may be completly unrelated to your string)).

( example: int pesudo_strlen(char *s)(char *s){char *p=s;while(*p)p++;return p-s;} )

Also, in your example,
 char lel[] = "wat";
The string will be statically allocated, so the compiler may place more than one null byte after it, for alignment purposes.

Name: Anonymous 2009-01-19 19:44

>>28
No, bitch, nobody said they were the only fucking choices. Dude liked Smalltalk, dude acknowledged that it was too slow, dude made a compromise and based it on C because it's performance oriented and writing C compilers is relatively easy.

Name: Anonymous 2009-01-19 19:45

>>38
s/(char *s)(char *s)/(char *s)//

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List