BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

div and mod troubles!

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Dominique MONTIN
Guest





PostPosted: Fri Mar 18, 2005 5:07 pm    Post subject: div and mod troubles! Reply with quote



Hi all

Why a so simple code does not compile. It generate syntax error !
It seems that the operators div and mod are note recognized by BCB6 !
Is there an options for that ???

{
int A,B,q;

A = 71;
B = 6;

q = A div B; // declaration syntax error here !!!
// idem with inr r = Amod B;
}

Thanks
Montin


Back to top
Gillmer J. Derge [TeamB]
Guest





PostPosted: Fri Mar 18, 2005 5:19 pm    Post subject: Re: div and mod troubles! Reply with quote



Dominique MONTIN wrote:
Quote:
Why a so simple code does not compile. It generate syntax error !
It seems that the operators div and mod are note recognized by BCB6 !

Correct. They aren't recognized by the C/C++ language either. :-)

Quote:
Is there an options for that ???

/ is div. % is mod.

--
Gillmer J. Derge [TeamB]

Back to top
Chris Uzdavinis (TeamB)
Guest





PostPosted: Fri Mar 18, 2005 6:26 pm    Post subject: Re: div and mod troubles! Reply with quote



"Dominique MONTIN" <dominique86.jacob (AT) laposte (DOT) fr> writes:

Quote:
Hi all

Why a so simple code does not compile. It generate syntax error !
It seems that the operators div and mod are note recognized by BCB6 !

There are no div and mod operators.

Quote:
Is there an options for that ???

No, you're thinking of a different language, perhaps?

Quote:
{
int A,B,q;

A = 71;
B = 6;

q = A div B; // declaration syntax error here !!!
// idem with inr r = Amod B;
}


"div" is / (on integral types)
"mod" is % (on integral types)

--
Chris (TeamB);

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 18, 2005 6:27 pm    Post subject: Re: div and mod troubles! Reply with quote


"Dominique MONTIN" <dominique86.jacob (AT) laposte (DOT) fr> wrote


Quote:
Why a so simple code does not compile.

Because it is not supposed to. It is not C++ code to begin with. The C++
operators are '/' and '%' for division and modulus, respectively. They are
not 'div' and 'mod'.

Quote:
It seems that the operators div and mod are note recognized by BCB6 !

'div' and 'mod' are not C++ instructions to begin with. '/' and '%', on the
other hand, are.

q = A / B;
r = A % B;


Gambit



Back to top
Liz Albin
Guest





PostPosted: Fri Mar 18, 2005 10:44 pm    Post subject: Re: div and mod troubles! Reply with quote

On Fri, 18 Mar 2005 18:07:31 +0100, Dominique MONTIN wrote:

Quote:
Why a so simple code does not compile. It generate syntax error !
It seems that the operators div and mod are note recognized by BCB6 !
Is there an options for that ???

because div isn't a c++ operator.

perhaps you meant

q = A/B;

and modulus is %

--
Good luck,

liz

Back to top
Helmut Giese
Guest





PostPosted: Fri Mar 18, 2005 11:07 pm    Post subject: Re: div and mod troubles! Reply with quote

Hi,
the other postings have already explained what those operators are in
C (C++).
I take it that you have a Pascal background. If this is true, you will
have similar trouble with other operators - Pascal makes them
"textual" (like div, mod, xor, etc.) while C makes them, well, let's
call it "symbolic". That's not really a big problem, because the
compiler will produce an error if you happen to use the Pascal-like
form and you can look up the correct way to do it in C.

However, there is one thing you _really_ should try to memorize:
In Pascal you say
if a = b then begin ...
In C you would have to say
if ( a == b ) { ...
BUT here is somewhat of a problem
if ( a = b ) { ...
(note the '=' instead of '==') is also legal C, however its meaning is
totally different from what a Pascal programmer might expect:
- it assigns b to a and
- evaluates to 'true' if a (and b) are != 0 (<> 0 in Pascal).

So this is eventually a big trap for Pascal programmers, because,
unlike misused operators like 'div' or 'mod'; it _will_ _compile_ -
however, the result will be far off from their expectations.

I would recommend PC-Lint (www.gimpel.com) for you: if ever you wonder
about some C code which compiles but produces unexpected results, let
Lint check it - you'll be a much better C programmer a lot earlier
(I've been there).
HTH
Helmut Giese
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Mar 18, 2005 11:17 pm    Post subject: Re: div and mod troubles! Reply with quote


"Helmut Giese" <hgiese (AT) ratiosoft (DOT) com> wrote


Quote:
BUT here is somewhat of a problem
if ( a = b ) { ...
(note the '=' instead of '==') is also legal C

Although legal, the compiler does check to see what the statement is
actually doing and will usually flag the statement as a "possibly incorrect
assignment" warning.


Gambit



Back to top
Dominique MONTIN
Guest





PostPosted: Mon Mar 21, 2005 8:39 am    Post subject: Re: div and mod troubles! Reply with quote

Thanks all !

I was "polluted" by my pascal background as helmut guess.
Montin

"Helmut Giese" <hgiese (AT) ratiosoft (DOT) com> a écrit dans le message de
news:423b5b14.26888390 (AT) forums (DOT) borland.com...
Quote:
Hi,
the other postings have already explained what those operators are in
C (C++).
I take it that you have a Pascal background. If this is true, you will
have similar trouble with other operators - Pascal makes them
"textual" (like div, mod, xor, etc.) while C makes them, well, let's
call it "symbolic". That's not really a big problem, because the
compiler will produce an error if you happen to use the Pascal-like
form and you can look up the correct way to do it in C.

However, there is one thing you _really_ should try to memorize:
In Pascal you say
if a = b then begin ...
In C you would have to say
if ( a == b ) { ...
BUT here is somewhat of a problem
if ( a = b ) { ...
(note the '=' instead of '==') is also legal C, however its meaning is
totally different from what a Pascal programmer might expect:
- it assigns b to a and
- evaluates to 'true' if a (and b) are != 0 (<> 0 in Pascal).

So this is eventually a big trap for Pascal programmers, because,
unlike misused operators like 'div' or 'mod'; it _will_ _compile_ -
however, the result will be far off from their expectations.

I would recommend PC-Lint (www.gimpel.com) for you: if ever you wonder
about some C code which compiles but produces unexpected results, let
Lint check it - you'll be a much better C programmer a lot earlier
(I've been there).
HTH
Helmut Giese



Back to top
Dominique MONTIN
Guest





PostPosted: Mon Mar 21, 2005 8:55 am    Post subject: Re: div and mod troubles! Reply with quote

A new question.
div and mod appears in the list of arithmetic operators in the HELP of
BorlandC++ builder 5.
It seems strange ?
Dominique


"Helmut Giese" <hgiese (AT) ratiosoft (DOT) com> a écrit dans le message de
news:423b5b14.26888390 (AT) forums (DOT) borland.com...
Quote:
Hi,
the other postings have already explained what those operators are in
C (C++).
I take it that you have a Pascal background. If this is true, you will
have similar trouble with other operators - Pascal makes them
"textual" (like div, mod, xor, etc.) while C makes them, well, let's
call it "symbolic". That's not really a big problem, because the
compiler will produce an error if you happen to use the Pascal-like
form and you can look up the correct way to do it in C.

However, there is one thing you _really_ should try to memorize:
In Pascal you say
if a = b then begin ...
In C you would have to say
if ( a == b ) { ...
BUT here is somewhat of a problem
if ( a = b ) { ...
(note the '=' instead of '==') is also legal C, however its meaning is
totally different from what a Pascal programmer might expect:
- it assigns b to a and
- evaluates to 'true' if a (and b) are != 0 (<> 0 in Pascal).

So this is eventually a big trap for Pascal programmers, because,
unlike misused operators like 'div' or 'mod'; it _will_ _compile_ -
however, the result will be far off from their expectations.

I would recommend PC-Lint (www.gimpel.com) for you: if ever you wonder
about some C code which compiles but produces unexpected results, let
Lint check it - you'll be a much better C programmer a lot earlier
(I've been there).
HTH
Helmut Giese



Back to top
Alan Bellingham
Guest





PostPosted: Mon Mar 21, 2005 9:40 am    Post subject: Re: div and mod troubles! Reply with quote

"Dominique MONTIN" <dominique86.jacob (AT) laposte (DOT) fr> wrote:

Quote:
A new question.
div and mod appears in the list of arithmetic operators in the HELP of
BorlandC++ builder 5.
It seems strange ?

Yes. As I recall, those refer to a particular (Formula One?) component,
and are terribly, terribly misleading, since the help pages in question
don't indicate that.

Alan Bellingham
--
ACCU Conference 2005 - 20-23 April, Randolph Hotel, Oxford, UK

Back to top
Andrew Fenton
Guest





PostPosted: Mon Mar 21, 2005 2:25 pm    Post subject: Re: div and mod troubles! Reply with quote


"Alan Bellingham" <alanb (AT) episys (DOT) com> wrote

Quote:
"Dominique MONTIN" <dominique86.jacob (AT) laposte (DOT) fr> wrote:

Yes. As I recall, those refer to a particular (Formula One?) component,
and are terribly, terribly misleading, since the help pages in question
don't indicate that.

Alan Bellingham
--
ACCU Conference 2005 - 20-23 April, Randolph Hotel, Oxford, UK

Just a guess, but maybe somebody attempted to adapt help files for Delphi to
BCB+ and missed something. I am assuming that Delphi matches Pascal with is
arithmetic operators.

Andrew



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Mar 21, 2005 4:40 pm    Post subject: Re: div and mod troubles! Reply with quote


"Dominique MONTIN" <dominique86.jacob (AT) laposte (DOT) fr> wrote


Quote:
div and mod appears in the list of arithmetic operators
in the HELP of BorlandC++ builder 5.

I just looked, and they they do NOT appear.


Gambit



Back to top
Alan Bellingham
Guest





PostPosted: Mon Mar 21, 2005 4:58 pm    Post subject: Re: div and mod troubles! Reply with quote

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote:

Quote:
I just looked, and they they do NOT appear.

They do on mine - and they appear to be talking about Delphi.

(I did an F1 on 'mod')

Alan Bellingham
--
ACCU Conference 2005 - 20-23 April, Randolph Hotel, Oxford, UK

Back to top
Bob Gonder
Guest





PostPosted: Mon Mar 21, 2005 8:50 pm    Post subject: Re: div and mod troubles! Reply with quote

Dominique MONTIN wrote:

Quote:
A new question.
div and mod appears in the list of arithmetic operators in the HELP of
BorlandC++ builder 5.
It seems strange ?

What is the exact topic of the help page?
Does it also say "Object Pascal" at the top of the page?

Only div and mod I could find were....

#include <stdlib.h>
div_t div(int numer, int denom);

#include <math.h>
double fmod(double x, double y);

Functions, not operators.



Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Mon Mar 21, 2005 10:23 pm    Post subject: Re: div and mod troubles! Reply with quote

Andrew Fenton wrote:

Quote:
Just a guess, but maybe somebody attempted to adapt help files for
Delphi to BCB+ and missed something. I am assuming that Delphi
matches Pascal with is arithmetic operators.

Andrew,

Yes, div and mod are standard Delphi operators. But AFAIK, Alan is
right about div and mod and the components.
--
Rudy Velthuis [TeamB] http://rvelthuis.bei.t-online.de

"It is now possible for a flight attendant to get a pilot pregnant."
- Richard J. Ferris, president of United Airlines

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.