473,385 Members | 1,958 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,385 software developers and data experts.

Simple but interesting issue

Hi All,

What is the differece between following code:

#define sbyte m_sbyte
typedef signed char m_sbyte;

and

#typedef signed char sbyte

Actually the first two lines of code solves the decleration
confliction issue. When sbyte is decleared as "unsigned char", the
first two lines of code will allow you to use the sbytes and signed
char. Anyone konws why?

Mar 16 '07 #1
9 1735
Mike wrote:
Hi All,

What is the differece between following code:

#define sbyte m_sbyte
typedef signed char m_sbyte;

and

#typedef signed char sbyte
The second is illegal, as there's no #typedef preprocessor
directive. Did you mean

typedef signed char sbyte;

?
Actually the first two lines of code solves the decleration
confliction issue.
What declaration conflict issue?
When sbyte is decleared as "unsigned char", the
first two lines of code will allow you to use the sbytes and signed
char. Anyone konws why?
I've no idea what you mean. Can you be more specific?

--
Chris "electric hedgehog" Dollin
The shortcuts are all full of people using them.

Mar 16 '07 #2
On 16 Mar, 14:07, "Mike" <mail...@gmail.comwrote:
Hi All,

What is the differece between following code:

#define sbyte m_sbyte
Tell the precompiler to replace the string "sbyte" with "m_sbyte" in
the source code.
typedef signed char m_sbyte;
Tell the compiler that "m_sbyte" means "signed char".
>
and

#typedef signed char sbyte
(pre-)compiler error - "#typedef" is not recognised.

Either you meant :-
"typedef signed char sbyte"
which tells the compiler that "sbyte" means "signed char"

or you meant
"#define signed char sbyte"
which tells the precompiler to replace all instances of "signed" with
"char sbyte".
Actually the first two lines of code solves the decleration
confliction issue. When sbyte is decleared as "unsigned char", the
first two lines of code will allow you to use the sbytes and signed
char. Anyone konws why?
I don't know what you are trying to say.

How about cutting and pasting some real code, preferably a small but
complete example, and showing us what problem you are encountering?

Mar 16 '07 #3
On Mar 16, 10:19 am, Chris Dollin <chris.dol...@hp.comwrote:
Mike wrote:
Hi All,
What is the differece between following code:
#define sbyte m_sbyte
typedef signed char m_sbyte;
and
#typedef signed char sbyte

The second is illegal, as there's no #typedef preprocessor
directive. Did you mean

typedef signed char sbyte;

?
Actually the first two lines of code solves the decleration
confliction issue.

What declaration conflict issue?
When sbyte is decleared as "unsigned char", the
first two lines of code will allow you to use the sbytes and signed
char. Anyone konws why?

I've no idea what you mean. Can you be more specific?

--
Chris "electric hedgehog" Dollin
The shortcuts are all full of people using them.
Sorry about the confusion. Here is the case:

In module A, sbyte is declared as unsigned char;
In module B, sbyte is declared as singed char;

When both modules are compiled together, there will be declaration
confliction. Now if you use the first two lines of code in module B.
Everything is OK, no need to change any code in Module A and B.

Mar 16 '07 #4
Mike wrote:
Sorry about the confusion. Here is the case:

In module A, sbyte is declared as unsigned char;
In module B, sbyte is declared as singed char;
Well, I'd say that was a mistake. Especially giving `unsigned
char` the abbreviation `sbyte`. I'll be giving /that/ programmer
no biscuit.
When both modules are compiled together, there will be declaration
confliction.
Not unless those types are declared in the /headers/ of the
compilation units. (I assume they're not being compiled as
a single unit -- that way madness lies.)
Now if you use the first two lines of code in module B.
Everything is OK, no need to change any code in Module A and B.
Even better is to fix the typedefs, in any one of several ways:

* if the typedefs aren't needed in the headers, take them out.

* if the typedefs are supposed to be the same thing, abstract
them out into a common header file.

* if the typedefs are supposed to be different things, apply
whatever your C-doesn't-have-namespaces-but module naming
convention rules are.

--
Chris "unsigned character" Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/

Mar 16 '07 #5
Mike wrote On 03/16/07 10:46,:
[...]

In module A, sbyte is declared as unsigned char;
In module B, sbyte is declared as singed char;
<fx: sniff, sniff Is something burning?

(Sorry, but the idea of a singed char is a matchless
inadvertent pun. I couldn't resist giving it some light,
even if I now catch heat for topicality abuse. Let the
flame wars begin, so we may smoke out the humor-impaired!)

--
Er*********@sun.com
Mar 16 '07 #6
In article <11*********************@o5g2000hsb.googlegroups.c om>,
Mike <ma*****@gmail.comwrote:
#define sbyte m_sbyte
typedef signed char m_sbyte;
>Sorry about the confusion. Here is the case:

In module A, sbyte is declared as unsigned char;
In module B, sbyte is declared as singed char;

When both modules are compiled together, there will be declaration
confliction. Now if you use the first two lines of code in module B.
Everything is OK, no need to change any code in Module A and B.
Presumably the #define and typedef appear in B after the inclusion of
the header file for A. The result is that B doesn't really use sbyte
at all, because all occurences of it after the #define will be replaced
with m_sbyte.

This sort of hack is quite common when dealing with existing libraries
that have name clashes, but you have to be very careful - should *all*
the uses of sbyte in module B be the signed version? - and where
possibly you should try to resolve the underlying name clash. Many
other languages have some kind of namespace mechanism to solve this.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 16 '07 #7
Eric Sosman wrote, On 16/03/07 15:08:
Mike wrote On 03/16/07 10:46,:
>[...]

In module A, sbyte is declared as unsigned char;
In module B, sbyte is declared as singed char;

<fx: sniff, sniff Is something burning?

(Sorry, but the idea of a singed char is a matchless
inadvertent pun. I couldn't resist giving it some light,
even if I now catch heat for topicality abuse. Let the
flame wars begin, so we may smoke out the humor-impaired!)
It's probably the flame wars that singed the char in the first place!
--
Flash Gordon
Mar 16 '07 #8
Flash Gordon wrote:
Eric Sosman wrote, On 16/03/07 15:08:
>Mike wrote On 03/16/07 10:46,:
>>[...]

In module A, sbyte is declared as unsigned char;
In module B, sbyte is declared as singed char;

<fx: sniff, sniff Is something burning?

(Sorry, but the idea of a singed char is a matchless
inadvertent pun. I couldn't resist giving it some light,
even if I now catch heat for topicality abuse. Let the
flame wars begin, so we may smoke out the humor-impaired!)

It's probably the flame wars that singed the char in the first place!
I believe singed chars have to be displayed in a sans-serif font.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Mar 16 '07 #9
Eric Sosman <Er*********@sun.comwrites:
[...]
Let the flame wars begin, so we may smoke out the humor-impaired!
That's not funny!

Oh, wait, never mind.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 16 '07 #10

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

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
11
by: darcykahle | last post by:
I have stumbled upon an interesting issue with regard to compaction of an access frontend database which resides on a DFS target that utilizes FRS to mirror the sharepoint, and I was wondering if...
44
by: Neil Cerutti | last post by:
In Rob Pike's style guide he urges the following: Simple rule: include files should never include include files. If instead they state (in comments or implicitly) what files they need...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
121
by: jacob navia | last post by:
Hi guys I have written this small parser to print out the functions defined in a C file. This is an example of parsing in C, that I want to add to my tutorial. Comments (and bug reports) are...
27
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
1
by: Radhey Krishna | last post by:
A very interesting problem for a simple requirement and not easily available solution: How would I create a button which will allow the user to specify where the file to be downloaded will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.