Three stupid C questions

J

Jean-Claude ROVIER

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

Seebs

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:

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
 
N

Nobody

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).
 
E

Eric Sosman

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

Jean-Claude ROVIER

Are you sure ??!! This looks crazy.
With the usual C libraries, the dispose procedure is named
free(pointer).

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

Ian Collins

Are you sure ??!! This looks crazy.


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

Keith Thompson

Jean-Claude ROVIER said:
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.
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.
 
S

Seebs

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

Keith Thompson

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

Actually, "not (a<>0)" is a bit crazy; the C equivalent would be
"!(a!=0)".

[...]
 
I

iC and iC++

  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.

I suggest you purchase an excellent book called The Complete
Reference, 4th Ed. [Paperback] by Helbert schildt

http://www.amazon.com/C-Complete-Re...=sr_1_8?s=books&ie=UTF8&qid=1283460406&sr=1-8

Before I got this book, I had to deal with a lot of asswipes in this
forum. After I got a hold of this book, it has become my first and
most of the time, last place of reference.
 
S

Seebs

I suggest you purchase an excellent book called The Complete
Reference, 4th Ed. [Paperback] by Helbert schildt

To the OP: iC is messing with you here. The book is spectacularly
bad, riddled with errors, and one of the worst sources you could pick
for learning about C. Recommending this to new posters is some sort
of hazing thing, like sending people for a "left-handed monkey wrench"
or whatever the pranks are these days.

-s
 
N

Nick Keighley

I suggest you purchase an excellent book called The Complete
Reference, 4th Ed. [Paperback] by Helbert schildt

To the OP:  iC is messing with you here.  The book is spectacularly
bad, riddled with errors, and one of the worst sources you could pick
for learning about C.  Recommending this to new posters is some sort
of hazing thing, like sending people for a "left-handed monkey wrench"
or whatever the pranks are these days.

go to stores and ask them to give you a "long weight"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top