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

strange function syntax

GS
I am doing my first real embedded programming project and the supplied
device libraries have a function definition that looks like this:

void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

where
INTDEF = some #defined integer
INTABS = some absolute integer (e.g. 2)
PTRDEF = some #defined pointer

The reason I ask is that my program is getting hung up (i.e. program
execution freezes without any exceptions/errors) on a call to this type of
function, but only when I compile with a certain amount of optimization
(everything works fine w/o optimization). This could be a compiler problem
I imagine but I'd like to know what the above statement does.

Thanks for your help.
Nov 14 '05 #1
26 2134
GS wrote:
I am doing my first real embedded programming project and the supplied
device libraries have a function definition that looks like this:

void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

where
INTDEF = some #defined integer
INTABS = some absolute integer (e.g. 2)
PTRDEF = some #defined pointer
How is FCN #defined?

The reason I ask is that my program is getting hung up (i.e. program
execution freezes without any exceptions/errors) on a call to this type of
function, but only when I compile with a certain amount of optimization
(everything works fine w/o optimization). This could be a compiler problem
I imagine but I'd like to know what the above statement does.


A good strategy is to strip your program stepwise until you end up with
the smallest possible program that still shows this behaviour. Post the
resulting code here to allow for detailed help.

Some user programming errors [dis]appear when fiddling compiler/linker
options. I know we programmers tend to start looking for the fault in
'others' (e.g., libraries written by a colleague, the compiler or the
wheather). I've (almost) learned to first blame myself :-)

Case

Nov 14 '05 #2
GS
FCN is just the function name, there's no #define of it.
void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

where
INTDEF = some #defined integer
INTABS = some absolute integer (e.g. 2)
PTRDEF = some #defined pointer
How is FCN #defined?

options. I know we programmers tend to start looking for the fault in
'others' (e.g., libraries written by a colleague, the compiler or the
wheather). I've (almost) learned to first blame myself :-)

Yes, well, this is a parallel effort to my personal code review.

Thanks again.
Nov 14 '05 #3
GS wrote:

I am doing my first real embedded programming project and the supplied
device libraries have a function definition that looks like this:

void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

where
INTDEF = some #defined integer
INTABS = some absolute integer (e.g. 2)
PTRDEF = some #defined pointer

The reason I ask is that my program is getting hung up (i.e. program
execution freezes without any exceptions/errors) on a call to this type of
function, but only when I compile with a certain amount of optimization
(everything works fine w/o optimization). This could be a compiler problem
I imagine but I'd like to know what the above statement does.


You're going to have to reveal more about `INTDEF' and
the like, and show their actual definitions. Otherwise,
people will just be making guesses.

--
Er*********@sun.com
Nov 14 '05 #4
GS
OK but I don't know how it will help:

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F /* ptr to mem location */

this syntax compiles, shouldn't there be some general meaning??

You're going to have to reveal more about `INTDEF' and
the like, and show their actual definitions. Otherwise,
people will just be making guesses.

--
Er*********@sun.com

Nov 14 '05 #5

A: Because people don't read from bottom to top.
Q: Why is top-posting deprecated?

GS wrote:

OK but I don't know how it will help:

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F /* ptr to mem location */

this syntax compiles, shouldn't there be some general meaning??

You're going to have to reveal more about `INTDEF' and
the like, and show their actual definitions. Otherwise,
people will just be making guesses.


Putting these definitions back into the original
code fragment, I get the still incomplete

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F /* ptr to mem location */
void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

.... which most definitely will compile. There must be more
#define's or other machinery lurking in the background, and you
haven't shown what it is.

"Doctor, it hurts!"

"What hurts?"

"I don't know how it will help you to know that, but it's
my knee that hurts."

"Your knee, eh? Which one?"

"What is this, the Spanish Inquisition?"

--
Er*********@sun.com
Nov 14 '05 #6
Eric Sosman wrote:
[..]
Putting these definitions back into the original
code fragment, I get the still incomplete

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F /* ptr to mem location */
void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

... which most definitely will compile. [...]

^
not

The Flying Fickle Finger of Fate fumbles the
keyboard yet again ...

--
Er*********@sun.com
Nov 14 '05 #7
In <cD*****************@twister.socal.rr.com> "GS" <no**@none.net> writes:
FCN is just the function name, there's no #define of it.
> void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};


In this case, you don't have a C question: this is not valid C syntax.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #8
GS
> > Putting these definitions back into the original
code fragment, I get the still incomplete

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F /* ptr to mem location */
void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};


What more do you want?? change INTABS to 2 and you have the whole thing:

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F
void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF};

I believe that this is specifying a single instruction by its opcode and
arguments, however I've never seen this syntax before. Why the processor
would hang on this instruction is another mystery.

Thanks for all the jokes.
Nov 14 '05 #9
GS

"Dan Pop" <Da*****@cern.ch> wrote in message
news:c6**********@sunnews.cern.ch...
In <cD*****************@twister.socal.rr.com> "GS" <no**@none.net> writes:
FCN is just the function name, there's no #define of it.
> void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};


In this case, you don't have a C question: this is not valid C syntax.


Well it does compile using Metrowerks codewarrior 9. I've never seen the
syntax before. The code isn't #defined for a particular compiler either, so
I'd be surprised if it was specific to metrowerks.
Nov 14 '05 #10
GS wrote:
Putting these definitions back into the original
code fragment, I get the still incomplete

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F /* ptr to mem location */
void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

What more do you want?? change INTABS to 2 and you have the whole thing:

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F
void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF};

I believe that this is specifying a single instruction by its opcode and
arguments, however I've never seen this syntax before. Why the processor
would hang on this instruction is another mystery.


Why the compiler would accept it is another mystery,
as it isn't valid C. Not even close, not at all. End
of story, as far as the C language is concerned. If it's
some kind of compiler-specific non-conforming C-with-bells
extension, you'd better seek help on a newsgroup devoted
to the bell-bearing compiler in question.
Thanks for all the jokes.


You're welcome. Good bye.

--
Er*********@sun.com
Nov 14 '05 #11
GS wrote:
FCN is just the function name, there's no #define of it.


Put

#undef FCN

right here (i.e., just before the presumable use of
macro FCN below). I wonder if it still compiles then.

Could you please show us the line of code where FCN is
called as a function. Or, what is the context in which
FCN exists? Are there any C preprocessor flags with -DFCN?
Is there any preprocessor invoked that was supplied by the
vendor of the OS, or whatever environment you use? Have
a close look at the build output of Metrowerks.
void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

where
INTDEF = some #defined integer
INTABS = some absolute integer (e.g. 2)
PTRDEF = some #defined pointer


How is FCN #defined?


options. I know we programmers tend to start looking for the fault in
'others' (e.g., libraries written by a colleague, the compiler or the
wheather). I've (almost) learned to first blame myself :-)


Yes, well, this is a parallel effort to my personal code review.

Thanks again.


Nov 14 '05 #12
GS wrote:
#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F
void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF};

I believe that this is specifying a single instruction by its opcode and
arguments, however I've never seen this syntax before. Why the processor
would hang on this instruction is another mystery.


I have seen something similar as one of the winning
entries of the OCCC (Obfuscated C Code Contest) somewhere
in the 90s. It looked something like:

int main[] = { 0xeefa, 0xed48, 0x45ed, ....... };

Is this valid C? But is compiled and ran on a PDP11-70
printing "Hello world!" I believe.

Case

Nov 14 '05 #13
Eric Sosman wrote:

A: Because people don't read from bottom to top.
Q: Why is top-posting deprecated?

Deprecated? It was never standard ;)


Brian Rodenborn
Nov 14 '05 #14
In <y1*****************@twister.socal.rr.com> "GS" <no**@none.net> writes:

"Dan Pop" <Da*****@cern.ch> wrote in message
news:c6**********@sunnews.cern.ch...
In <cD*****************@twister.socal.rr.com> "GS" <no**@none.net> writes:
>FCN is just the function name, there's no #define of it.
>
>> > void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};
In this case, you don't have a C question: this is not valid C syntax.


Well it does compile using Metrowerks codewarrior 9.


Not if you invoke it as a standard C compiler. According to the
definition of the C programming language, this code:

1. Requires a diagnostic.

2. Has no defined semantics.
I've never seen the
syntax before. The code isn't #defined for a particular compiler either, so
I'd be surprised if it was specific to metrowerks.


As I said, not even metrowerks will silently accept it when invoked as a
C compiler.

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

On Thu, 29 Apr 2004, Case - wrote:

I have seen something similar
Not similar to GS's code, since at least the IOCCC entry parses
correctly. The syntax

void foo(void) = { ... }

is quite simply invalid, whereas the syntax

int foo[] = { ... }

is a standard way to define an array.
as one of the winning
entries of the OCCC (Obfuscated C Code Contest) somewhere
in the 90s. It looked something like:

int main[] = { 0xeefa, 0xed48, 0x45ed, ....... };

Is this valid C? But is compiled and ran on a PDP11-70
printing "Hello world!" I believe.


It is not conforming C on a hosted implementation, according to
N869, because the declaration of 'main' as an array with external
linkage precludes the definition of 'main' as a function with
external linkage. Thus we have no 'main' function in a hosted
environment, which yields UB.
In a non-hosted environment, anything goes.
If you make it 'static int main[] = ...', then I think it is
valid C (assuming 'int main()' is defined in a different TU).

That this IOCCC code worked on a PDP-11 compiler is not surprising;
it might even work on a modern DOS-based compiler (with appropriate
adjustments to the machine-code part of the program). But since in
standard C, data is never code, this is definitely *not* guaranteed
to do anything in particular.

HTH,
-Arthur
Nov 14 '05 #16
Case - <no@no.no> writes:
GS wrote:
#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F
void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF};
I believe that this is specifying a single instruction by its opcode
and
arguments, however I've never seen this syntax before. Why the processor
would hang on this instruction is another mystery.


I have seen something similar as one of the winning
entries of the OCCC (Obfuscated C Code Contest) somewhere
in the 90s. It looked something like:

int main[] = { 0xeefa, 0xed48, 0x45ed, ....... };

Is this valid C? But is compiled and ran on a PDP11-70
printing "Hello world!" I believe.


Actually, here's the program:

short main[] = {
277, 04735, -4129, 25, 0, 477, 1019, 0xbef, 0, 12800,
-113, 21119, 0x52d7, -1006, -7151, 0, 0x4bc, 020004,
14880, 10541, 2056, 04010, 4548, 3044, -6716, 0x9,
4407, 6, 5568, 1, -30460, 0, 0x9, 5570, 512, -30419,
0x7e82, 0760, 6, 0, 4, 02400, 15, 0, 4, 1280, 4, 0,
4, 0, 0, 0, 0x8, 0, 4, 0, ',', 0, 12, 0, 4, 0, '#',
0, 020, 0, 4, 0, 30, 0, 026, 0, 0x6176, 120, 25712,
'p', 072163, 'r', 29303, 29801, 'e'
};

It won the 1984 contest. The way the compiler and linker happened to
work on that particular system, it created a symbol called "main"
referring to a chunk of memory with those particular values, which
happened to be machine instructions. The runtime system didn't care
whether "main" was created by a function definition or by an array
definition, so it would execute the code.

Worse yet, the first word was a PDP-11 branch instruction; on a VAX,
execution would start at the second word. So the program would
execute on either a VAX or a PDP-11; the output was a smiley.

*However*, GS's code fragment has (what appears to be) a function
declaration, not an array declaration, so it's not doing the same
thing. Remove the '=' and add a semicolon before the '}', and you
have a legal function definition that doesn't do anything.

The fact that FCN is in all-caps makes me suspect that it's defined as
a macro. If FCN is not a macro, the code fragment is not legal C. If
FCN is a macro, it might conceivably be legal C, but I can't think of
a definition that would it legal. Probably GS's compiler implements
some extension for machine code insertions. Such extensions are
beyond the scope of this newsgroup, and we can't guess why the
processor is hanging.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #17
Keith Thompson <ks***@mib.org> writes:
[...]
Actually, here's the program:

short main[] = { [...] };

[...]

Like all truly great IOCCC entries, it led to a rule change.
Excessively target-dependent entries were banned after the 1984
contest.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #18
Eric Sosman <Er*********@sun.com> wrote in message news:<40**************@sun.com>...
> void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};


... If it's some kind of compiler-specific non-conforming C-with-bells
extension...


Of course it's a compiler-specific C-with-bells extension. Of course
it's not _strictly_ conforming, but it is 'conforming' under the
definition of the standards.

--
Peter
Nov 14 '05 #19
Though, this perfectly normal in comp.lang.postscript is.

Thanks,

Olle

Default User wrote:
Eric Sosman wrote:
A: Because people don't read from bottom to top.
Q: Why is top-posting deprecated?


Deprecated? It was never standard ;)


Brian Rodenborn


--
Olavi Sakari
For direct email, please replace the digits in my name
with their alphabetic representatives.

Nov 14 '05 #20


GS wrote:
I am doing my first real embedded programming project and the supplied
device libraries have a function definition that looks like this:

void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};

where
INTDEF = some #defined integer
INTABS = some absolute integer (e.g. 2)
PTRDEF = some #defined pointer

The reason I ask is that my program is getting hung up (i.e. program
execution freezes without any exceptions/errors) on a call to this type of
function, but only when I compile with a certain amount of optimization
(everything works fine w/o optimization). This could be a compiler problem
I imagine but I'd like to know what the above statement does.

Thanks for your help.


This is a wild guess. But is the the code trying the generate a function
address? Or call a function by its address?
Nov 14 '05 #21
Keith Thompson wrote:
GS wrote:
> #define INTDEF 0x08F8
> #define PTRDEF 0xFFFFFA1F
> void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF};
[...] The fact that FCN is in all-caps makes me suspect that it's defined
as a macro. If FCN is not a macro, the code fragment is not legal
C. If FCN is a macro, it might conceivably be legal C, but I can't
think of a definition that would it legal.


#define FCN(x) *p; int a[]

Jeremy.
Nov 14 '05 #22
Olavi Sakari wrote:
Though, this perfectly normal in comp.lang.postscript is.


It is not normal here. And that is what counts. If
I ever need to discuss postscript I'll top post if
required to.

What is the bid deal?

--
Thomas.

Nov 14 '05 #23
Arthur J. O'Dwyer wrote:
On Thu, 29 Apr 2004, Case - wrote:
I have seen something similar

Not similar to GS's code, since at least the IOCCC entry parses
correctly. The syntax

void foo(void) = { ... }

is quite simply invalid, whereas the syntax

int foo[] = { ... }

is a standard way to define an array.


Yes I know.
as one of the winning
entries of the OCCC (Obfuscated C Code Contest) somewhere
in the 90s. It looked something like:

int main[] = { 0xeefa, 0xed48, 0x45ed, ....... };

Is this valid C? But is compiled and ran on a PDP11-70
printing "Hello world!" I believe.

It is not conforming C on a hosted implementation, according to
N869, because the declaration of 'main' as an array with external
linkage precludes the definition of 'main' as a function with
external linkage. Thus we have no 'main' function in a hosted
environment, which yields UB.
In a non-hosted environment, anything goes.
If you make it 'static int main[] = ...', then I think it is
valid C (assuming 'int main()' is defined in a different TU).

That this IOCCC code worked on a PDP-11 compiler is not surprising;
it might even work on a modern DOS-based compiler (with appropriate
adjustments to the machine-code part of the program). But since in
standard C, data is never code, this is definitely *not* guaranteed
to do anything in particular.

HTH,


The only 'help' I needed was related to C standard conformance.
Thanks for the explanation!
-Arthur


Nov 14 '05 #24
Jeremy Yallop wrote:
Keith Thompson wrote:
GS wrote:

#define INTDEF 0x08F8
#define PTRDEF 0xFFFFFA1F
void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF};

[...]
The fact that FCN is in all-caps makes me suspect that it's defined
as a macro. If FCN is not a macro, the code fragment is not legal
C. If FCN is a macro, it might conceivably be legal C, but I can't
think of a definition that would it legal.

#define FCN(x) *p; int a[]


I knew it. Where did you find this?

Jeremy.


Nov 14 '05 #25
Peter Nilsson wrote:

Eric Sosman <Er*********@sun.com> wrote in message news:<40**************@sun.com>...
> > void FCN(void) = { INTDEF, INTABS, (unsigned short) PTRDEF};


... If it's some kind of compiler-specific non-conforming C-with-bells
extension...


Of course it's a compiler-specific C-with-bells extension. Of course
it's not _strictly_ conforming, but it is 'conforming' under the
definition of the standards.


True, in the sense that

public static void main(String[] args) { }

is "conforming:" The compiler can attach any meaning it likes
to a non-C construct, and can document that extension and
perhaps even make it useful. However, a conforming compiler
must also issue a diagnostic; the O.P. doesn't specifically
tell us that there's no diagnostic, but he never mentioned
any and wrote that "this syntax compiles." If it compiles
without a diagnostic, I believe the compiler is non-conforming.

--
Er*********@sun.com
Nov 14 '05 #26

On Fri, 30 Apr 2004, Case - wrote:

Jeremy Yallop wrote:
Keith Thompson wrote:
GS wrote:

>#define INTDEF 0x08F8
>#define PTRDEF 0xFFFFFA1F
>void FCN(void) = {INTDEF, 2, (unsigned short) PTRDEF}; The fact that FCN is in all-caps makes me suspect that it's defined
as a macro. If FCN is not a macro, the code fragment is not legal
C. If FCN is a macro, it might conceivably be legal C, but I can't
think of a definition that would it legal.


#define FCN(x) *p; int a[]


I knew it. Where did you find this?


He wrote it. It's not too difficult. Expanding this macro
in GS's code gives

void *p; int a[] = {INTDEF, 2, (unsigned short) PTRDEF};

which is obviously valid C code; it defines a (void *) object called
'p' and an array of three ints called 'a'.
It doesn't do anything useful, though --- all it does is make the
code compile. In particular, it's still a syntax error to try to
"call" FCN using the FCN() syntax.

-Arthur
Nov 14 '05 #27

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

Similar topics

7
by: Aaron Prohaska | last post by:
I have just run into a problem where I have a page that posts back to itself to execute code, except when the page does the post back it somehow executes code that is in our home page for the site....
2
by: Alexander Stippler | last post by:
Can someone explain the following construct to me: What is not clear to me is what the argument to foo is. A pointer to a member? template <class U> static char foo(void (U::*)(void)); ...
3
by: Gary Besta | last post by:
I am trying to add a simple case statement to a stored procedure or user defined function. However when I try and save the function/procedure I get 2 syntax errors. Running the query in query...
2
by: Olaf | last post by:
I have a frameset page witch contains the myFuc() function. The function is accessed from a page in one of the frames in the frameset. An example is shown below. <input...
8
by: Harvey Twyman | last post by:
I have code written under the CCS 'C' Compiler to run on a PIC microcontroller. Code Extract: ------------------------------- char a,b,c; ------------------------------- c = ( a == b );...
9
by: sylsau | last post by:
Hi, I am doing a little program who calculates the permutation of a set of vertex. I use the recursivity for this calcul. My function who calculate the permutations : void permutation(set...
6
by: Chad | last post by:
I'm not too sure if the question would fall under comp.lang.c or some kind of compiler newsgroup. I'm going to ask anyhow. Given the following: #include <stdio.h> int main(void) { int a =...
11
by: Dagwood Bumstead | last post by:
I play around with js a little... I just don't get this. The file below is just trying out some things... it does exactly what I want (hides/displays some things, no big deal) The problem is...
19
by: david | last post by:
I took old code and decided to modify it a bit, and I just noticed that it does not compile at all and before server one of severs (main) crashed in the system it was working fine (I am really sure...
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...
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
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?
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...

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.