473,404 Members | 2,213 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,404 software developers and data experts.

Problem with #define

I am working on socket programming, encountered a new and strange
problem today.

I am using #define PORT 80, before main(), and I am calling PORT in one
of the statments inside main(), I get an error, I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.
I am sure that #define works in C, any idea why my code is not
programming, i can also email my code if required.

Thanks

Harshit

Nov 14 '05 #1
9 2016
"Harshit"
I am working on socket programming, encountered a new and strange
problem today.

I am using #define PORT 80, before main(), and I am calling PORT in one
of the statments inside main(), I get an error, I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.
I am sure that #define works in C, any idea why my code is not
programming, i can also email my code if required.


I believe this lies outside the scope of ISO C. Maybe one of the others
knows where to discuss this. MPJ
Nov 14 '05 #2
On Wed, 15 Dec 2004 04:25:29 -0800, Harshit wrote:
I am working on socket programming, encountered a new and strange
problem today.
Well C itself doesn't support socket programming, but your problem may be
(and sounds like) a language issue rather than relating to that.
I am using #define PORT 80, before main(), and I am calling PORT in one
of the statments inside main(), I get an error,
Saying "I get an error" isn't particularly useful. Detailing exactly what
error you get can and probably will be.
I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.
Given the amount of detail here it is difficult to say much more than
"there is a bug in your code". Of course your compiler may have a bug but
at this stage that is a much less likely cause.
I am sure that #define works in C, any idea why my code is not
programming, i can also email my code if required.


Post your code here. Preferably post a MINIMAL but COMPLETE program that
demonstrates the problem, and cut and paste real code - it doesn't help
anybody if we end up just debugging transcription errors. If you can
come up with a version of problem code that doesn't use socket facilities
all the better, that might even help you figure out the cause.

Lawrence
Nov 14 '05 #3
"Merrill & Michele" <be********@comcast.net> wrote:
"Harshit"
I am working on socket programming, encountered a new and strange
problem today.

I am using #define PORT 80, before main(), and I am calling PORT in one
of the statments inside main(), I get an error, I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.

I am sure that #define works in C, any idea why my code is not
programming, i can also email my code if required.

Don't email code. Reduce it to the smallest compilable sample that still
shows the problem, then post it to the group. If you email it to someone
random and that person makes a mistake in his reply, who is going to
correct him? Here in comp.lang.c, though, you get free nit-picking by
professional nit-pickers from all over the world. And believe me, some
of us have elevated ye picking of ye nitte to a veritable art :-)
Oh, and don't forget to include the _exact_ error you get ("It doesn't
work" is an error report I expect from users, not from my colleagues),
including whether it occurs at compile time or at run time, and under
what circumstances.

Without such information, it's impossible to give a reliable solution to
your problem. As a wild guess, though, maybe something else in your code
(an #included header, perhaps) is already #defining PORT?
I believe this lies outside the scope of ISO C.


Why ever would you think that? #define most definitely is ISO C, has
been so since C89, and AFAIK was K&R as well.

Richard
Nov 14 '05 #4
On Wed, 15 Dec 2004 04:25:29 -0800, Harshit said to the parser:
I am working on socket programming, encountered a new and strange problem
today.

I am using #define PORT 80, before main(), and I am calling PORT in one of
the statments inside main(), I get an error, I don't know why this error
is occuring. If i remove PORT in the statement and substitute it by 80, my
code works fine.


Just at a guess (you don't provide any code), perhaps you have written:

#define PORT 80;

instead of:
#define PORT 80

The former substitutes 80 and a semi-colon. The latter substitutes just
80.

If 80 works fine, and your #define is correct, then using PORT should just
work, so there must be something else going on. Posting some code would
help the group help you.
Michael

Nov 14 '05 #5
"Richard Bos"
"Merrill & Michele"
"Harshit"
I am working on socket programming, encountered a new and strange
problem today.

I am using #define PORT 80, before main(), and I am calling PORT in one of the statments inside main(), I get an error, I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.

I am sure that #define works in C, any idea why my code is not
programming, i can also email my code if required.


Don't email code. Reduce it to the smallest compilable sample that still
shows the problem, then post it to the group. If you email it to someone
random and that person makes a mistake in his reply, who is going to
correct him? Here in comp.lang.c, though, you get free nit-picking by
professional nit-pickers from all over the world. And believe me, some
of us have elevated ye picking of ye nitte to a veritable art :-)
Oh, and don't forget to include the _exact_ error you get ("It doesn't
work" is an error report I expect from users, not from my colleagues),
including whether it occurs at compile time or at run time, and under
what circumstances.

Without such information, it's impossible to give a reliable solution to
your problem. As a wild guess, though, maybe something else in your code
(an #included header, perhaps) is already #defining PORT?
I believe this lies outside the scope of ISO C.


Why ever would you think that? #define most definitely is ISO C, has
been so since C89, and AFAIK was K&R as well.


The part that I thought was OT was any type of network activity. I would be
thrilled to find out that I'm completely wrong. You (Richard) posted about
a month back about the non-Standard nature of some activity being counted
along the horizon of a month. Do you recall the post? MP
Nov 14 '05 #6
Harshit wrote:

I am using #define PORT 80, before main(), and I am calling PORT in one
of the statments inside main(), I get an error, I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.

I am sure that #define works in C, any idea why my code is not
programming, i can also email my code if required.


Many C define problems are the result of a terminal ; in the
define.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #7
Merrill & Michele <be********@comcast.net> wrote:
"Richard Bos"
"Merrill & Michele"
"Harshit"
I am using #define PORT 80, before main(), and I am calling PORT in
one
of the statments inside main(), I get an error, I don't know why this
error is occuring. If i remove PORT in the statement and substitute it
by 80, my code works fine.

I believe this lies outside the scope of ISO C.
Why ever would you think that? #define most definitely is ISO C, has
been so since C89, and AFAIK was K&R as well.

The part that I thought was OT was any type of network activity. I would be
thrilled to find out that I'm completely wrong. You (Richard) posted about
a month back about the non-Standard nature of some activity being counted
along the horizon of a month. Do you recall the post? MP


The OP wasn't asking about anything network related but just about
some problems (s)he has with a #define directive - and that's about
as on-topic as you can get here.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #8
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"Merrill & Michele" <be********@comcast.net> wrote:
"Harshit"
> I am working on socket programming, encountered a new and strange
> problem today.
>
> I am using #define PORT 80, before main(), and I am calling PORT in one
> of the statments inside main(), I get an error, I don't know why this
> error is occuring. If i remove PORT in the statement and substitute it
> by 80, my code works fine.
>
> I am sure that #define works in C, any idea why my code is not
> programming, i can also email my code if required.


Don't email code. Reduce it to the smallest compilable sample that still
shows the problem, then post it to the group.

[...]

(In this case, a compilable sample won't show the problem, assuming
that "I get an error" refers to a compilation failure.)

Agreed, but even posting just a couple of snippets of actual code,
along with the actual error message, is likely to be more useful than
a vague description. (By "actual code" I mean lines cut-and-pasted
from the actual source you're trying to compile, not re-typed.) For
example, if someone posted something like this:

] I am working on socket programming, encountered a new and strange
] problem today.
]
] I am using #define PORT 80, before main():
]
] #define PORT 80;
]
] and I am using PORT in one of the statements inside main():
]
] some_function(an_arg, PORT, another_arg);
]
] I get an error:
]
] foobar.c:42: error: parse error before ';' token
]
] I don't know why this error is occuring. If I remove PORT in the
] statement and substitute it by 80:
]
] some_function(an_arg, 80, another_arg);
]
] my code works fine.

we could have figured out the problem immediately. (I'm assuming, as
several other people here have, that it's a semicolon problem.)

This isn't always the case, of course. Sometimes nothing less than
the actual complete source file that you're feeding to the compiler
will do. But the more specific (not paraphrased) information you can
give us, the more likely we are to be able to help you.

--
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.
Nov 14 '05 #9
"Keith Thompson"
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"Merrill & Michele" <be********@comcast.net> wrote:
"Harshit"
> I am working on socket programming, encountered a new and strange
> problem today.
>
> I am using #define PORT 80, before main(), and I am calling PORT in one > of the statments inside main(), I get an error, I don't know why this
> error is occuring. If i remove PORT in the statement and substitute it > by 80, my code works fine.
>
> I am sure that #define works in C, any idea why my code is not
> programming, i can also email my code if required.


Don't email code. Reduce it to the smallest compilable sample that still
shows the problem, then post it to the group.

[...]

(In this case, a compilable sample won't show the problem, assuming
that "I get an error" refers to a compilation failure.)

Agreed, but even posting just a couple of snippets of actual code,
along with the actual error message, is likely to be more useful than
a vague description. (By "actual code" I mean lines cut-and-pasted
from the actual source you're trying to compile, not re-typed.) For
example, if someone posted something like this:

] I am working on socket programming, encountered a new and strange
] problem today.
]
] I am using #define PORT 80, before main():
]
] #define PORT 80;
]
] and I am using PORT in one of the statements inside main():
]
] some_function(an_arg, PORT, another_arg);
]
] I get an error:
]
] foobar.c:42: error: parse error before ';' token
]
] I don't know why this error is occuring. If I remove PORT in the
] statement and substitute it by 80:
]
] some_function(an_arg, 80, another_arg);
]
] my code works fine.

we could have figured out the problem immediately. (I'm assuming, as
several other people here have, that it's a semicolon problem.)

This isn't always the case, of course. Sometimes nothing less than
the actual complete source file that you're feeding to the compiler
will do. But the more specific (not paraphrased) information you can
give us, the more likely we are to be able to help you.


[SCOLDS BOY NOT TO TOUCH MOUSE]

I guess my contention is that the OP seems not to know where standard c
stops. This is critical to know in software development. Myself, I don't
know where c stops, but in clc I err on the side of strict interpretation.
MPJ
Nov 14 '05 #10

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

Similar topics

0
by: Pallav | last post by:
i'm trying to build a lookup sine table to run some code in an embedded processor without floating point unit. the table is 256 values for 360 degrees. my code is below. the fixed point base is...
2
by: s.subbarayan | last post by:
Dear all, I have one peculiar problem with me for which I need ur inputs how to implement it: I have 2 registers each 8 bit wide. The first register stores: Register Map:...
7
by: hierro | last post by:
I have a list of functions (all with suffix T). For each one, I need to implement the following: FunctionT() { if (some_condition) { // do some conversion first FunctionW(); // then do some...
11
by: Fernando Barsoba | last post by:
Hi all, I very much need your help here guys.. I'm working on a IPSec implementation, and when almost finished, I found a considerable problem. I'm sending a particular array + a key to a...
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
39
by: elnanni | last post by:
I've a problem in the use of threads, they don't work as i want them to. Here's the code, the problem is that if i uncomment the //pthread_join(thread_ID, NULL);, the main program stops until the...
1
by: marionane | last post by:
Hi all! I`m using this implementation of the rc6 encryption on an embedded webserver, 80186: #include <stdio.h> /* RC6 is parameterized for w-bit words, b bytes of key, and * r rounds. The...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
3
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.