Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Three stupid C questions

Reply
Thread Tools

Three stupid C questions

 
 
Jean-Claude ROVIER
Guest
Posts: n/a
 
      08-31-2010
Hi All,

I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
world.
Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
any suggestions ) and start learning C/C++, I need to translate a C
prog into TP.

Here are the supid questions:

1st:

I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
is.
If the program does 'MyPointer = p++' what does this mean?

1) MyPointer = p; increment p of 1;
2) MyPointer = p; Increment p of SizeOf(CStruct);
3) increment p of 1; MyPointer = p;
4) increment p op SizeOf(CStruct); MyPointer = p;
5) something else?

Second stupid question:

'if !(a = b)' means

1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
'=')
2) a=b and if b=0 then....
3) something else?

Third stupid question:

When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
couldn't find the 'dealloc' function in the prog.

If someone knows where to find basic c++ help (*.hlp, *.doc,...) on the
net...

Thanks a lot for your help, and please excuse the stupidity of my
questions.
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      08-31-2010
On 2010-08-31, Jean-Claude ROVIER <(E-Mail Removed)> wrote:
> I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
> world.


What's that?

> Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
> any suggestions )


djgpp or whatever they call it these days. Free. Pretty good.

> and start learning C/C++,


C and C++ are two different languages. Pick one.

> Here are the supid questions:


> 1st:


> I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
> is.
> If the program does 'MyPointer = p++' what does this mean?


I have no idea what you're writing here.

In general, "x = p++", in C, means the same as:
x = p;
p = p + 1;

That is to say, x is assigned the previous value of p, and p is incremented.
(When a pointer in C is incremented, it points to the next object of whatever
type it's a pointer to, so if you have a pointer to a CStruct, it will
point to the following CStruct.)

> 'if !(a = b)' means


This is a syntax error. It needs ()s.

> 1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
> '=')
> 2) a=b and if b=0 then....
> 3) something else?


if (!expr) {
}

executes the code if expr is equal to zero.

a = b

assigns b's value into a, then yields a's value.

Thus,

if (!(a = b)) {
/* code */
}

assigns b's current value into a, and if the result is zero, executes code.

> Third stupid question:


> When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
> couldn't find the 'dealloc' function in the prog.


Very good question. "_fmalloc" is not a standard C function. On most
implementations I've used, all program memory is freed automatically
on exit, but this function may behave differently.

> If someone knows where to find basic c++ help (*.hlp, *.doc,...) on the
> net...


No clue, I don't do C++.

> Thanks a lot for your help, and please excuse the stupidity of my
> questions.


Stupidity is bearable, but I can tell you something you MUST do:

Be. More. Careful.

C is an extremely picky language. The punctuation MATTERS. You cannot
just paraphrase or type from memory unless your memory is a LOT better
than it apparently is now. If you are making the same kinds of errors
in transcription and translation that you made in creating this post, you
are not producing anything that will be of value to you or anyone else.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      08-31-2010
On Tue, 31 Aug 2010 21:20:13 +0000, Seebs wrote:

>> Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
>> any suggestions )

>
> djgpp or whatever they call it these days. Free. Pretty good.


djgpp is gcc for DOS. MinGW is gcc for Windows.

Microsoft offer a free version of Visual C++ ("Express" edition).

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      09-01-2010
On 8/31/2010 5:02 PM, Jean-Claude ROVIER wrote:
>
> Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
> any suggestions ) and start learning C/C++, I need to translate a C
> prog into TP.
>
> Here are the supid questions:
>
> 1st:
>
> I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
> is.
> If the program does 'MyPointer = p++' what does this mean?
>
> 1) MyPointer = p; increment p of 1;
> 2) MyPointer = p; Increment p of SizeOf(CStruct);


Yes to both. MyPointer (assuming it's a pointer of a suitable
type) gets the old value of p, and p advances by one -- that is,
to the next CStruct, whether a CStruct is one byte or forty-two bytes
in size. Pointer arithmetic in C is done in units of the thing that
is pointed at; it can never produce a pointer to the "middle" of such
an object (unless you're doing evil type-punning).

> 3) increment p of 1; MyPointer = p;
> 4) increment p op SizeOf(CStruct); MyPointer = p;


Your phraseology is strange to me and I may have misunderstood
you, but no: The ++ *post*fix operator yields the original value of
its operand, while the ++*pre*fix operator yields the new value. To
avoid any confusion that "pointerness" may be causing:

int x = 42;
int y = x++; /* now y == 42, x == 43 */
int z = ++x; /* now z == 44, x == 44 */

> 5) something else?
>
> Second stupid question:
>
> 'if !(a = b)' means
>
> 1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
> '=')


No: Your observation that `=' is not `==' is correct. C's `='
is like Pascal's `:=', and C's `==' is like Pascal's `='.

> 2) a=b and if b=0 then....


Yes. Or more exactly, "a=b and if a==0". The value of b may or
may not be zero (consider b == 0.42 with an integer a); it's the value
assigned to a that matters.

> 3) something else?
>
> Third stupid question:
>
> When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
> couldn't find the 'dealloc' function in the prog.


This _fmalloc() function isn't part of C, but part of somebody's
C-with-extras framework. Sorry; I don't know what its rules are.

> Thanks a lot for your help, and please excuse the stupidity of my
> questions.


The stupidest question of all is the one you failed to ask when
you should have.

--
Eric Sosman
(E-Mail Removed)lid
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      09-01-2010
On Tue, 2010-08-31, Seebs wrote:
> On 2010-08-31, Jean-Claude ROVIER <(E-Mail Removed)> wrote:
>> I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
>> world.

>
> What's that?


Turbo Pascal, I imagine. Last time I saw it Ronald Reagan was
president of the US ...

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Jean-Claude ROVIER
Guest
Posts: n/a
 
      09-01-2010
Behind China Blue Eyes writes:
>> Second stupid question:
>>
>> 'if !(a = b)' means

>
> a := b; if not (a<>0) then ...
>
>> 2) a=b and if b=0 then....


Are you sure ??!! This looks crazy.

>> Third stupid question:
>>
>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
>> exit? I couldn't find the 'dealloc' function in the prog.

>
> With the usual C libraries, the dispose procedure is named
> free(pointer).


If I do this I am getting a Segmention Fault...
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      09-01-2010
On 09/ 2/10 10:04 AM, Jean-Claude ROVIER wrote:
> Behind China Blue Eyes writes:
>>> Second stupid question:
>>>
>>> 'if !(a = b)' means

>>
>> a := b; if not (a<>0) then ...
>>
>>> 2) a=b and if b=0 then....

>
> Are you sure ??!! This looks crazy.
>
>>> Third stupid question:
>>>
>>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
>>> exit? I couldn't find the 'dealloc' function in the prog.

>>
>> With the usual C libraries, the dispose procedure is named
>> free(pointer).

>
> If I do this I am getting a Segmention Fault...


Then whatever you are trying to free wasn't allocated with one of the
standard allocation functions.

--
Ian Collins
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-01-2010
Jean-Claude ROVIER <(E-Mail Removed)> writes:
> Behind China Blue Eyes writes:
>>> Second stupid question:
>>>
>>> 'if !(a = b)' means

>>
>> a := b; if not (a<>0) then ...
>>
>>> 2) a=b and if b=0 then....

>
> Are you sure ??!! This looks crazy.


The original 'if !(a = b)' is a syntax error. If you'll post the actual
line of code, we can explain it.

>>> Third stupid question:
>>>
>>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
>>> exit? I couldn't find the 'dealloc' function in the prog.

>>
>> With the usual C libraries, the dispose procedure is named
>> free(pointer).

>
> If I do this I am getting a Segmention Fault...


You need to read the documentation for _fmalloc(). It's non-standard.

The standard allocation function in C is malloc(); malloc() calls should
be matched with free() calls.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Moi
Guest
Posts: n/a
 
      09-01-2010
On Wed, 01 Sep 2010 22:04:02 +0000, Jean-Claude ROVIER wrote:

> Behind China Blue Eyes writes:
>>> Second stupid question:
>>>
>>> 'if !(a = b)' means

>>
>> a := b; if not (a<>0) then ...
>>
>>> 2) a=b and if b=0 then....

>
> Are you sure ??!! This looks crazy.
>
>>> Third stupid question:
>>>
>>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
>>> exit? I couldn't find the 'dealloc' function in the prog.

>>
>> With the usual C libraries, the dispose procedure is named
>> free(pointer).

>
> If I do this I am getting a Segmention Fault...


There is an error on line 42.

AvK

 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      09-01-2010
On 2010-09-01, Jean-Claude ROVIER <(E-Mail Removed)> wrote:
> Behind China Blue Eyes writes:
>>> Second stupid question:
>>> 'if !(a = b)' means


>> a := b; if not (a<>0) then ...


>>> 2) a=b and if b=0 then....


> Are you sure ??!! This looks crazy.


If you don't want to listen to the answers people give, why did you
ask?

One of the big differences between C and Pascal is that C is a lot more
prone to "side-effects" -- expressions which change things along with
evaluating to values.

>> With the usual C libraries, the dispose procedure is named
>> free(pointer).


> If I do this I am getting a Segmention Fault...


This is too unspecific for us to do much but point out that "_fmalloc"
is not part of the *usual* C libraries, so you'll need to make your own
guesses or read some documentation.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Three stupid C questions: ++,... jean francois C Programming 23 06-13-2012 07:28 AM
Re: Three Mobile --> Skype on three (Non-three [Symbian - Nokia] handsets) Harry Stottle UK VOIP 0 01-05-2010 08:59 AM
Stupid question. Please, only stupid responders. If you're not sureif you're stupid, you probably aren't. =?ISO-8859-1?Q?R=F4g=EAr?= Computer Support 6 07-18-2005 05:11 AM
stupid stupid stupid kpg MCSE 17 11-26-2004 02:59 PM
stupid test questions and stupid awnsers in Measureup 70-320 test john MCAD 0 10-13-2004 11:43 PM



Advertisments