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

preprozessor and #define Problem

Hello,

I have a problem with a macro which will return a pointer.
In the header trolley_position_SL_GR is defined:
#define trolley_position_SL_GR ((real_T*) ssGetPWorkValue(S,4))

The function ssGetPWorkValue return a pointer on real_T. If I use something
like:

real_T *test;
test = (real_T*) ssGetPWorkValue(S,4);
//or
test = *((real_T*) ssGetPWorkValue(S,4)+4); // for example

everything works fine.
If I use:
teal_T *test;
test = *(trolley_position_SL_GR+6);
Now, I get a segmentation fault and if I set it in brackets like :
test = *((trolley_position_SL_GR)+6);
it works!

Can someone explain this phenomenon?´I use Visual Studio 6 as c-compiler.

Thank you,

Daniel
Nov 14 '05 #1
8 1164
Daniel Wild <da********@web.de> scribbled the following:
Hello, I have a problem with a macro which will return a pointer.
In the header trolley_position_SL_GR is defined:
#define trolley_position_SL_GR ((real_T*) ssGetPWorkValue(S,4)) The function ssGetPWorkValue return a pointer on real_T. If I use something
like: real_T *test;
test = (real_T*) ssGetPWorkValue(S,4);
//or
test = *((real_T*) ssGetPWorkValue(S,4)+4); // for example everything works fine.
If I use:
teal_T *test;
test = *(trolley_position_SL_GR+6);
Now, I get a segmentation fault and if I set it in brackets like :
test = *((trolley_position_SL_GR)+6);
it works! Can someone explain this phenomenon?´I use Visual Studio 6 as c-compiler.


I can't explain it, but I noticed that you're assigning a value of type
real_T into a variable of type real_T *. Depending on what type real_T
is, this might cause undefined behaviour.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The question of copying music from the Internet is like a two-barreled sword."
- Finnish rap artist Ezkimo
Nov 14 '05 #2
"Daniel Wild" <da********@web.de> wrote in message
news:cb************@hades.rz.uni-saarland.de...
Hello,

I have a problem with a macro which will return a pointer.
In the header trolley_position_SL_GR is defined:
#define trolley_position_SL_GR ((real_T*) ssGetPWorkValue(S,4))

The function ssGetPWorkValue return a pointer on real_T.
Then why do you cast it's return value?
If I use something like:

real_T *test;
test = (real_T*) ssGetPWorkValue(S,4);
//or
test = *((real_T*) ssGetPWorkValue(S,4)+4); // for example

everything works fine.
If I use:
teal_T *test;
test = *(trolley_position_SL_GR+6);
Now, I get a segmentation fault and if I set it in brackets like :
test = *((trolley_position_SL_GR)+6);
it works!

Can someone explain this phenomenon?´
Please post the smallest _compilable_ snippet that exhibits the problem. Don't retype, use
copy and paste. [Merely getting the code to postable form may well provide you with the
answer.]
I use Visual Studio 6 as c-compiler.


If that's relevant, then chances are you're posting to the wrong group.

--
Peter
Nov 14 '05 #3
"Daniel Wild" <da********@web.de> wrote in message news:<cb************@hades.rz.uni-saarland.de>...
Hello,

I have a problem with a macro which will return a pointer.
In the header trolley_position_SL_GR is defined:
#define trolley_position_SL_GR ((real_T*) ssGetPWorkValue(S,4))

The function ssGetPWorkValue return a pointer on real_T. If I use something
like:

real_T *test;
test = (real_T*) ssGetPWorkValue(S,4);
//or
test = *((real_T*) ssGetPWorkValue(S,4)+4); // for example ^
Invalid Indirection, compiler ought to give a warning here. (*)

everything works fine.
If I use:
teal_T *test; ^^^^
real_T
test = *(trolley_position_SL_GR+6);
test = * ( ((real_T*) ssGetPWorkValue(S,4)) + 6 )

Read (*).
Now, I get a segmentation fault and if I set it in brackets like :
test = *((trolley_position_SL_GR)+6);


test = * ( ( ((real_T*) ssGetPWorkValue(S,4)) + 6 );

Read (*).

The fact that your program does not quite @work fine@ means that you
probably made a typo. Please @copy paste@ the code.

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 14 '05 #4
"Peter Nilsson" <ai***@acay.com.au> wrote in message news:<40********@news.rivernet.com.au>...
"Daniel Wild" <da********@web.de> wrote in message
news:cb************@hades.rz.uni-saarland.de...
Hello,

I have a problem with a macro which will return a pointer.
In the header trolley_position_SL_GR is defined:
#define trolley_position_SL_GR ((real_T*) ssGetPWorkValue(S,4))

The function ssGetPWorkValue return a pointer on real_T.


Then why do you cast it's return value?
If I use something like:

real_T *test;
test = (real_T*) ssGetPWorkValue(S,4);
//or
test = *((real_T*) ssGetPWorkValue(S,4)+4); // for example

everything works fine.
If I use:
teal_T *test;
test = *(trolley_position_SL_GR+6);
Now, I get a segmentation fault and if I set it in brackets like :
test = *((trolley_position_SL_GR)+6);
it works!

Can someone explain this phenomenon?´


Please post the smallest _compilable_ snippet that exhibits the problem. Don't retype, use
copy and paste. [Merely getting the code to postable form may well provide you with the
answer.]
I use Visual Studio 6 as c-compiler.


If that's relevant, then chances are you're posting to the wrong group.


Why can't this point be relevant in c.l.c? OP posted strictly
conforming code, unless of course you consider using user defined
types, directive or functions in c.l.c to be invalid. It is obviously
quite certain/obvious that OP thought that this comment might help in
better diagnosis of the problem.

Comments like these are 100% irrelevent and just waste my precious
little 28kbps bandwidth.

I am not impressed.

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 14 '05 #5
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
"Peter Nilsson" <ai***@acay.com.au> wrote in message

news:<40********@news.rivernet.com.au>...
...
Please post the smallest _compilable_ snippet that exhibits the problem.
Don't retype, use copy and paste. [Merely getting the code to postable
form may well provide you with the answer.]
I use Visual Studio 6 as c-compiler.


If that's relevant, then chances are you're posting to the wrong group.


Why can't this point be relevant in c.l.c? OP posted strictly
conforming code, unless of course you consider using user defined
types, directive or functions in c.l.c to be invalid. It is obviously
quite certain/obvious that OP thought that this comment might help in
better diagnosis of the problem.

Comments like these are 100% irrelevent and just waste my precious
little 28kbps bandwidth.

I am not impressed.


I'm not impressed with your assertion that the OP posted strictly conforming code,
particularly as in another post you point out typos and a required diagnostic.

You seem to have posted in angst over false premises. I'm afraid that's a waste of
everyone's bandwidth.

--
Peter
Nov 14 '05 #6
"Peter Nilsson" <ai***@acay.com.au> wrote in message news:<40******@news.rivernet.com.au>...
"Minti" <mi************@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
"Peter Nilsson" <ai***@acay.com.au> wrote in message

news:<40********@news.rivernet.com.au>...
...
Please post the smallest _compilable_ snippet that exhibits the problem.
Don't retype, use copy and paste. [Merely getting the code to postable
form may well provide you with the answer.]

> I use Visual Studio 6 as c-compiler.

If that's relevant, then chances are you're posting to the wrong group.


Why can't this point be relevant in c.l.c? OP posted strictly
conforming code, unless of course you consider using user defined
types, directive or functions in c.l.c to be invalid. It is obviously
quite certain/obvious that OP thought that this comment might help in
better diagnosis of the problem.

Comments like these are 100% irrelevent and just waste my precious
little 28kbps bandwidth.

I am not impressed.


I'm not impressed with your assertion that the OP posted strictly conforming code,
particularly as in another post you point out typos and a required diagnostic.

You seem to have posted in angst over false premises. I'm afraid that's a waste of
everyone's bandwidth.

Well it depends on what the meaning of "strictly conforming" is?. When
I said strictly conforming I _obviously_ meant that that the code did
not contain any feature that we might consider to be non standard. Non
standard as in having void main() etc. Yes bad terminology but why do
you think I should accept my mistake when you don't yours.

--
Imanpreet Singh Arora
isingh AT acm DOT org
Nov 14 '05 #7
"Minti" <mi************@yahoo.com> wrote...
"Peter Nilsson" <ai***@acay.com.au> wrote...
"Minti" <mi************@yahoo.com> wrote...
"Peter Nilsson" <ai***@acay.com.au> wrote...
> ...
> Please post the smallest _compilable_ snippet that exhibits the
> problem. Don't retype, use copy and paste. [Merely getting the
> code to postable form may well provide you with the answer.]
>
> > I use Visual Studio 6 as c-compiler.
>
> If that's relevant, then chances are you're posting to the wrong
> group.

Why can't this point be relevant in c.l.c? OP posted strictly
conforming code, unless of course you consider using user defined
types, directive or functions in c.l.c to be invalid. It is
obviously quite certain/obvious that OP thought that this comment
might help in better diagnosis of the problem.

Comments like these are 100% irrelevent and just waste my precious
little 28kbps bandwidth.

I am not impressed.
I'm not impressed with your assertion that the OP posted strictly
conforming code, particularly as in another post you point out typos
and a required diagnostic.

You seem to have posted in angst over false premises. I'm afraid
that's a waste of everyone's bandwidth.


Well it depends on what the meaning of "strictly conforming" is?


Try the one in the standards.
When I said strictly conforming I _obviously_ meant that that the code'
did not contain any feature that we might consider to be non standard.
Non standard as in having void main() etc.
Does your version of 'strictly conforming' include assignments involving incompatible
pointer types?
Yes bad terminology but why do you think I should accept my mistake when
you don't yours.


What mistake have I made?

You talked about considering 'user defined types, directive or functions in c.l.c to be
invalid'. Nowhere in my post did I say that was the case.

As far as I'm concerned, OP's can use as many functions and types as they like, so long as
they can be put in terms of ISO C and so long as the posted code is compilable or
trivially made compilable. Having to guess function prototypes and user types is not
something I consider acceptable. The less an OP defines, the less likely an ISO C answer
is going to be redily forthcoming.

Consider...

int foo(void *); /* this is ok */
typedef struct some_struct *real_T;

__cdecl __int64 foo(void *) /* this isn't */
typedef void * far real_T;

In the case of the former, where is the implementation relevant?

For the latter, do you really want clc to answer questions based on that?

--
Peter
Nov 14 '05 #8
In <40********@news.rivernet.com.au> "Peter Nilsson" <ai***@acay.com.au> writes:
"Daniel Wild" <da********@web.de> wrote in message
news:cb************@hades.rz.uni-saarland.de...
I use Visual Studio 6 as c-compiler.


If that's relevant, then chances are you're posting to the wrong group.


How can the OP know whether it's relevant or not? Since he doesn't, it's
safer to mention it.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #9

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

Similar topics

18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
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:...
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...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages 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...

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.