473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question About Strange 'C' Code Syntax ( Well strange to me anyway )

I have code written under the CCS 'C' Compiler to run on a PIC microcontroller.

Code Extract:

-------------------------------
char a,b,c;
-------------------------------
c = ( a == b );
-------------------------------

It also uses this syntax in "Function Calls" thus:

function ( a == b );
-------------------------------
function ( char x ) { ... }
-------------------------------

===========================================

Question:

What does this mean as my Hi-Tech 'C' Compiler doesn't understand it either?

===========================================

Harvey Twyman
About Me: http://www.Twyman.org.uk/CV

===========================================
Nov 13 '05 #1
8 2204
In article <6d**************************@posting.google.com >, Harvey Twyman wrote:
I have code written under the CCS 'C' Compiler to run on a PIC microcontroller.

Code Extract:

-------------------------------
char a,b,c;
Declares three char varaiables.
-------------------------------
c = ( a == b );
Assigns the result of the comparison between a and b to c (zero
if they are not eqal, non-zero otherwise). The type of c should
probably be "int", not "char".
It also uses this syntax in "Function Calls" thus:

function ( a == b );
Call function with the value zero if a equals b, otherwise call
it with a non-zero value.
function ( char x ) { ... }


Should probably be "int x".
In what way does you compiler not like this?
--
Andreas Kähäri
Nov 13 '05 #2
Andreas Kahari wrote:
In article <6d**************************@posting.google.com >, Harvey Twyman wrote:
c = ( a == b );


Assigns the result of the comparison between a and b to c (zero
if they are not eqal, non-zero otherwise).


Specifically, 1 otherwise.
function ( a == b );


Call function with the value zero if a equals b, otherwise call
it with a non-zero value.


Specifically, call it with the value 1.

Jeremy.
Nov 13 '05 #3
dis
"Harvey Twyman" <ha***********@yahoo.com> wrote in message
news:6d**************************@posting.google.c om...
I have code written under the CCS 'C' Compiler to run on a PIC microcontroller.
Code Extract:

-------------------------------
char a,b,c;
-------------------------------
c = ( a == b );
-------------------------------
Assigns to c the value of the expression a==b, which is either 0 or 1,
assuming the comparison is well defined.
It also uses this syntax in "Function Calls" thus:

function ( a == b );
-------------------------------
function ( char x ) { ... }
-------------------------------
Calls function with the value of the expression a==b for the first argument.
a==b is either 0 or 1, assuming the comparison is well defined.
===========================================

Question:

What does this mean as my Hi-Tech 'C' Compiler doesn't understand it either?
===========================================


See above.
Nov 13 '05 #4
Harvey Twyman wrote:

I have code written under the CCS 'C' Compiler to run on a PIC microcontroller.

Code Extract:

-------------------------------
char a,b,c;
-------------------------------
c = ( a == b );
-------------------------------

It also uses this syntax in "Function Calls" thus:

function ( a == b );
-------------------------------
function ( char x ) { ... }
-------------------------------

===========================================

Question:

What does this mean as my Hi-Tech 'C' Compiler doesn't understand it either?

===========================================

Harvey Twyman
About Me: http://www.Twyman.org.uk/CV

===========================================


It ought to work. There seems to be no prohibition against
assigning the result of a logical operation to a 'char' type.
But maybe your Hi-Tech 'C' Compiler would prefer assignment
to an integer?

Either is permissible, as the example shows.

int main(void)
{
char a,b,c,d;
int k;

a = 'w';
b = 'z';
d = 'w';

c = ( a == b );
k = ( a == b );
printf( " %c%c%c%d%d\n", a,b,d,c,k ); // outputs wzw00

c = ( a == d );
k = ( a == d );
printf( " %c%c%c%d%d\n", a,b,d,c,k ); // outputs wzw11
return 0;
}

--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo".
Nov 13 '05 #5
Andreas Kahari <ak*******@freeshell.org> writes:
In article <6d**************************@posting.google.com >, Harvey Twyman wrote:
I have code written under the CCS 'C' Compiler to run on a PIC microcontroller.

Code Extract:

-------------------------------
char a,b,c;


Declares three char varaiables.
-------------------------------
c = ( a == b );


Assigns the result of the comparison between a and b to c (zero
if they are not eqal, non-zero otherwise). The type of c should
probably be "int", not "char".


Specifically, one "otherwise". As to whether it should be a char
or an int: char may save a little space, and the values 0 and 1
are definitely representable in a char. No problems.

--
Micah J. Cowan
mi***@cowan.name
Nov 13 '05 #6
ha***********@yahoo.com (Harvey Twyman) writes:
I have code written under the CCS 'C' Compiler to run on a PIC
microcontroller.

Code Extract:

-------------------------------
char a,b,c;
-------------------------------
c = ( a == b );
-------------------------------

It also uses this syntax in "Function Calls" thus:

function ( a == b );
-------------------------------
function ( char x ) { ... }
-------------------------------

===========================================

Question:

What does this mean as my Hi-Tech 'C' Compiler doesn't understand it either?


It means either that the code fragments you posted don't correspond to
what you actually fed to the compiler, or that your compiler is broken
(more precisely, that your compiler doesn't conform to the C
standard).

If you'll post a small complete self-contained program (I suggest no
more than 20 lines) that exhibits the problem, along with the error
message you get when you try to compile it, we can help you determine
which it is.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #7
"Jeremy Yallop" <je****@jdyallop.freeserve.co.uk> wrote:
function ( a == b );


Call function with the value zero if a equals b, otherwise call
it with a non-zero value.


Specifically, call it with the value 1.


No, wrong way around. Call it with the value 1 if a equals b,
otherwise call it with the value 0.
Nov 13 '05 #8
ha***********@yahoo.com (Harvey Twyman) wrote in
news:6d**************************@posting.google.c om on Thu 23 Oct 2003
09:44:54a:
I have code written under the CCS 'C' Compiler to run on a PIC
microcontroller.

Code Extract:
Please, don't do this. At least post something that will compile, run, and
demonstrates the problem. The lines below, while mostly syntactically
correct, will not compile to anything remotely testable.

-------------------------------
char a,b,c;
This much is obvious, and is perfectly correct C.
-------------------------------
c = ( a == b );
This is, too, obvious to someone who knows C, but perhaps less than
obvious to someone who is not well-versed in how C handles the values of
comparison ops. If a and b compare equal, c will get the value 1. If they
compare unequal, c will get the value 0.

Note that those values are ints, not chars. Your compiler could reasonably
diagnose that as a problem. For safety, declare c as an int.
-------------------------------

It also uses this syntax in "Function Calls" thus:

function ( a == b );
A perfectly valid subroutine call. function() gets the value 1 if a == b
is true, and 0 if it is not.
-------------------------------
function ( char x ) { ... }
See above about trying to use the char type to hold the result of a
comparison op. Also, declare a return type for the subroutine. Use the
void keyword if it does not return a value, like so:

void func(int x)
{
printf("%d\n", x);
}

/* I think printf() does return a value, but ignoring it like that will
not create incorrect code. */
-------------------------------

===========================================

Question:

What does this mean as my Hi-Tech 'C' Compiler doesn't understand it
either?


If your 'C' compiler does not understand the foregoing, it is not
Standards-conformant and probably is not the correct tool for the job.

Unless, of course, the code you /didn't/ post is wrong. See, I really
can't tell from over here. Post a compilable version of your code and
we'll all consider it and tell you if it's non-Standard.

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Henning Kage | last post by:
I'm using Python only for some months now and I'm wondering, whether such assignments as above are creating bitwise copies of an object or just recieve a reference. That means I wanted to know,...
19
by: Carlos Ribeiro | last post by:
Hello all, Here I am using some deeply nested, tree-like data structures. In some situations I need to traverse the tree; the old-style way to do it is to write a recursive method on the node...
4
by: badbetty | last post by:
Hello and thank you for reading on (hopefully). How does one typecast the XMLREADER returned from the XSLTRANSFORM method 'transform' into XMLTEXTREADER, so it can be passed in to an...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
16
by: Justin Koivisto | last post by:
I am trying to create a query to use as a report record source. Below is what I want to do (this was tested and works with a MySQL web script): SELECT contacts.id, contacts.email,...
3
by: Schizoid Man | last post by:
Hi, I'm a novice whose just about migrating to C++ after cutting my teeth on C for a few years. To start with I'm using Microsoft's out-of-the-box Visual C++ Express Edition compiler and I...
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
7
by: krishna | last post by:
What is the need of this syntax for initializing values, isn't this ambiguous to function call? e.g., int func_name(20); this looks like function call (of course not totally as there is no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.