Jump to content

How much damage could I accidentally do with pointers?

Art Vandelay
Go to solution Solved by Ciccioo,

zero risk

your program will just crash, or not work properly

same for assembler

this is because your program doesn't really "see" the memory, but it uses a "virtual memory", it's like every executable has its own sandbox

there are ways to access memory outside of the sandbox, but you need more privileges and anyway it's not done via pointers, it's done via dedicated functions

I'm trying to learn C because I feel like it'll be useful, and I don't really see the point to object oriented C++ yet.

 

C seems to require pointers to do a lot of things, and I'm probably going to accidentally mess up an algorithm, causing the wrong memory address to be written to.

 

How much damage could this potentially cause? Is it enough to justify doing everything in a VM?

 

When I start learning assembly, I'm gonna get out a VM lol.

Link to comment
Share on other sites

Link to post
Share on other sites

As far as I know all reasonably modern operating systems will protect from any dangerous memory access. So you should be fine. I've never had any problems, just thrown a few fatal errors at run time.

My rig: 2600k(4.2 GHz) w/ Cooler Master hyper 212+, Gigabyte Z68-UD3H-B3, Powercolor 7870 xt(1100/1500) w/AIO mod,

8GB DDR3 1600, 120GB Kingston HyperX 3K SSD, 1TB Seagate, Antec earthwatts 430, NZXT H2

Verified max overclock, just for kicks: http://valid.canardpc.com/show_oc.php?id=2609399

Link to comment
Share on other sites

Link to post
Share on other sites

zero risk

your program will just crash, or not work properly

same for assembler

this is because your program doesn't really "see" the memory, but it uses a "virtual memory", it's like every executable has its own sandbox

there are ways to access memory outside of the sandbox, but you need more privileges and anyway it's not done via pointers, it's done via dedicated functions

Link to comment
Share on other sites

Link to post
Share on other sites

The kernel only has the privilege level to do something serious. Your program will just crash if you point to some section of memory out of its scope. 

CPU: Intel Core i5 2500K | Case: Bitfenix Prodigy | Motherboard: GA-H61N-USB3 | RAM: Corsair 8GB 1333 MHz Video CardEVGA GTX 660 Superclocked 2GB DDR5

Power Supply: Corsair CX 430 | SSD: Samsung 840 120GB | HDD: 2X Seagate Barracuda 500GB 7200rpm | Monitor Asus PB238Q & Asus PB278Q

Mouse: Lenovo N50 | Keyboard: Apple Pro Keyboard | Operating Systems: Hackintosh OS X 10.8.5 & Windows 8.1

Link to comment
Share on other sites

Link to post
Share on other sites

Pretty much what everyone else is saying...your program will just crash during run time.  Just make sure your remember to deallocate memory on the heap in your programs.  You must also be weary of dangling pointers - a pointer that is pointing to memory that is no longer allocated in your program. 

 

Also, I don't know why you would find no point in learning C++ for OOP design.  C++ has made outstanding improvements to the C language through its additions to class modeling.  In addition, OOP is very popular in modern programming languages today; so it certainly isn't pointless to learn at some point. 

Link to comment
Share on other sites

Link to post
Share on other sites

Also, I don't know why you would find no point in learning C++ for OOP design.  C++ has made outstanding improvements to the C language through its additions to class modeling.  In addition, OOP is very popular in modern programming languages today; so it certainly isn't pointless to learn at some point. 

For everything I'm doing, there doesn't seem to be a point in using OOP for anything I'm doing. When I get futher into university, I might find things where it makes more sense to use.

Link to comment
Share on other sites

Link to post
Share on other sites

For everything I'm doing, there doesn't seem to be a point

did you mean: "there doesn't seem to be a pointer"

ha!

ha ha!

ahhh...

alright... nevermind

Link to comment
Share on other sites

Link to post
Share on other sites

did you mean: "there doesn't seem to be a pointer"

ha!

ha ha!

ahhh...

alright... nevermind

post-1491-0-00110200-1395703662.jpg

Link to comment
Share on other sites

Link to post
Share on other sites

C is the greatest language. Good choice.

 

As for OOP, it's perfectly possible to implement basic OO design in C. It just lacks the syntactic sugar.

 

There's a free book on it http://www.cs.rit.edu/~ats/books/ooc.pdf

 

Not exactly light reading, but interesting nonetheless.

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×