Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!mit.eternal-september.org!.POSTED!not-for-mail From: Richard Newsgroups: comp.lang.c Subject: Re: memset Date: Sun, 20 Apr 2014 14:35:17 +0100 Organization: http://www.ieee.org/ Lines: 80 Message-ID: <87ppkcrune.fsf@gmail.com> References: <10bac1fc-2d9a-49e7-b4c3-0db6f6013b5a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mit.eternal-september.org; posting-host="bdee7d74bb5599725cdba9fe2a37525e"; logging-data="29357"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uzwtj0yaSfgisccF1SQFCVq5bu3FtM2Q=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:Nmpx95wjuoDE2WfZAIfzoLoZlp0= sha1:LK/5h3Wy8h3mIlWx6gAkDNCpeog= Xref: csiph.com comp.lang.c:43176 "Bill Cunningham" writes: > Michael Angelo Ravera wrote: > >> OK. Your fundamental lack of understanding is that of data >> representation. Programming in C is designed for people who >> understand data representation and not for people who don't. >> >> What's a pointer? A pointer is a value that represents where >> something is stored. You have to say "represents" dont you? Why not just say it points to where the data is? Sheesh. >> >> For most (it is intended and they are working on "all") data items in >> C, there is a way to obtain a pointer to it. This is often referred >> to as "dereferencing". For most pointers, there is a way to obtain NO it isnt. It's called referencing. Dereferencing is obtaining the data from the location pointed to by the pointer. https://en.wikipedia.org/wiki/Dereference_operator When being surly and elite and putting people down it's frequently better not to get wrapped up in your own twaddle. >> the data (or first item of data) to which it points, if such a >> reference would refer to something in the representation (otherwise >> you will have some kind of a problem -- ranging from "that's not what >> I meant" on up to "halt and catch fire".) >> >> So, let's look at memset: The first argument is a pointer to the >> beginning of the of the area of memory that you want to set to the >> particular value. >> This area may represent an array, a structure, a single data item >> ("scalar"), or a memory map of some device. The function doesn't know >> or really care all that much. If you tell it to blast '*'s to the >> memory map of a printer and your program has proper access to it, you >> will probably get a bunch of '*'s on the paper (or whatever the '*'s >> represent to the printer). The function memset just puts however many >> copies you say of whatever character you say in an area of memory >> that you say. It doesn't know what it is doing or whether it is doing >> what you want. It is very much like a screwdriver -- really good for >> tightening or removing screws, usable for drilling holes, can be made >> to pry things off of each other, really bad for jamming into your >> eye. >> >> So, the trick in getting memset to do what you want (like putting >> spaces into a character array where you are going to place a name of >> something, or putting '*'s into any eye catcher string), is to obtain >> a pointer to the beginning of the area, determining to what value you >> want to set everything, and obtaining a byte count for the thing that >> you want to set. >> >> Usually, you can obtain a pointer to the beginning of the >> representation of something simply dereferencing it with the "&" >> operator and you can obtain the size of the representation of the >> that thing by using either "sizeof" or, with some more complicated >> things, by using "offsetof". But, you need to supply sizeof with the >> representation of the entire thing that you want to set. In some >> cases, you will use offsetof (thing, >> last_variable_thing[number_of_last_variable_things]). > > Thanks Michael but I will have to admit; a lot of this is a little over > my head right now. There's just something about these pointers. But I guess > that's a common problem with persons who use C. I am a hobbyist. I have been > trying to learn C on and off for a long time. I take a break for a while and > I am finding learn as you go seems to slowly work. I appreciate any help > though. It doesn't go unnoticed. > > Bill > No. It doesn't ... lol. -- "Avoid hyperbole at all costs, its the most destructive argument on the planet" - Mark McIntyre in comp.lang.c