Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Possible C shorthand -- please help!

Reply
Thread Tools

Possible C shorthand -- please help!

 
 
almurph@altavista.com
Guest
Posts: n/a
 
      01-16-2009
Hi

Hope you can help me with this one. Is the following "C" code:

short somevar, MethodName();

shorthand for:

short somevar = MethodName();


where the MethodName() returns a short?


Would appreciate any comments/suggestions/explanations that you may
have.

Thanking you,
Al.
 
Reply With Quote
 
 
 
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      01-16-2009
On 16 Jan, 12:35, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> Hi
> * * * * Hope you can help me with this one. Is the following "C" code:
>
> short somevar, MethodName();
>
> * * * * shorthand for:
>
> short somevar = MethodName();
>
> * * * * where the MethodName() returns a short?


no. it means

short somevar;
short MethodName();

ie. the second bit is a function declaration, though not
a complete prototype. It is not used to initialise somevar
in the code given. somevar may be uninitialised, depending
if it has file scope or not.

<snip>

--
Nick Keighley

"Een schip op het strand is een baken in zee.
[A ship on the beach is a lighthouse to the sea.]"
- Dutch Proverb
 
Reply With Quote
 
 
 
 
August Karlstrom
Guest
Posts: n/a
 
      01-16-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi
>
> Hope you can help me with this one. Is the following "C" code:
>
> short somevar, MethodName();
>
> shorthand for:
>
> short somevar = MethodName();
>
>
> where the MethodName() returns a short?


No, it's a shorthand for

short somevar;
short MethodName();


August


(Note that C do not have "methods", only functions)
 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      01-16-2009
On 16 Jan, 12:43, August Karlstrom <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > Hi

>
> > * *Hope you can help me with this one. Is the following "C" code:

>
> > short somevar, MethodName();

>
> > * *shorthand for:

>
> > short somevar = MethodName();

>
> > * *where the MethodName() returns a short?

>
> No, it's a shorthand for
>
> short somevar;
> short MethodName();
>
> August
>
> (Note that C do not have "methods", only functions)


there's nothing to stop you calling things methods though.
He might be writing a compiler for something that does have
methods.

--
Nick Keighley
 
Reply With Quote
 
almurph@altavista.com
Guest
Posts: n/a
 
      01-16-2009
On Jan 16, 12:57*pm, (E-Mail Removed) wrote:
> On 16 Jan, 12:43, August Karlstrom <(E-Mail Removed)> wrote:
>
>
>
>
>
> > (E-Mail Removed) wrote:
> > > Hi

>
> > > * *Hope you can help me with this one. Is the following "C" code:

>
> > > short somevar, MethodName();

>
> > > * *shorthand for:

>
> > > short somevar = MethodName();

>
> > > * *where the MethodName() returns a short?

>
> > No, it's a shorthand for

>
> > short somevar;
> > short MethodName();

>
> > August

>
> > (Note that C do not have "methods", only functions)

>
> there's nothing to stop you calling things methods though.
> He might be writing a compiler for something that does have
> methods.
>
> --
> Nick Keighley- Hide quoted text -
>
> - Show quoted text -


Hi,

Just to let you know - i'm converting this C code into the
equivalent C#.NET code. That's why I wanted the clarification as
MethodName() returns a short so i think I have to do somethign like
this in C#.NET:

short somevar;
short someVar = MethodName();

Thanks,
Al.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      01-16-2009
"(E-Mail Removed)" <(E-Mail Removed)> writes:
<snip>
> Just to let you know - i'm converting this C code into the
> equivalent C#.NET code.


The best translations (I am talking about human language) here is
almost always by people who translate into their native tongue. A
similar rule applies to computer languages. You'll end up writing
better C# by asking C# experts how a particular C idiom should be
written in C#.

> That's why I wanted the clarification as
> MethodName() returns a short so i think I have to do somethign like
> this in C#.NET:
>
> short somevar;
> short someVar = MethodName();


That is almost certainly wrong. If the capital V is a typo the other
variable in not needed; if not you declare a variable twice.

--
Ben.
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      01-16-2009
(E-Mail Removed) wrote:

> On Jan 16, 12:57*pm, (E-Mail Removed) wrote:
>> On 16 Jan, 12:43, August Karlstrom <(E-Mail Removed)> wrote:
>> > (E-Mail Removed) wrote:
>> > > Hi

>>
>> > > Hope you can help me with this one. Is the following "C" code:

>>
>> > > short somevar, MethodName();

>>
>> > > shorthand for:

>>
>> > > short somevar = MethodName();

>>
>> > > where the MethodName() returns a short?

>>
>> > No, it's a shorthand for

>>
>> > short somevar;
>> > short MethodName();

>
> Just to let you know - i'm converting this C code into the
> equivalent C#.NET code. That's why I wanted the clarification as
> MethodName() returns a short so i think I have to do somethign like
> this in C#.NET:
>
> short somevar;
> short someVar = MethodName();


If your C source /really is/

short somevar, MethodName(); // A

then you /must not/ translate it into

short somevar = MethodName(); // B

because that would not have the correct effect. The effect of
(A) is to declare that `somevar` is a short variable and that
`MethodName` is a function taking an unspecified argument list
and returning a short; it /does not/ call `MethodName()`. The
C# form (B) is, offtopically and IIRC, a declaration of `shortvar`
and a /call/ to `MethodName()`, assigning the result of the
latter to the newly-declared variable.

[This is assuming that (A) isn't from C code so old that any
kind of literal translation, into C89, C99, C++, C#, or C-side,
would be more boneheaded than a shipful of Minbari.]

--
"- born in the lab under strict supervision -", /Genetesis/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      01-16-2009
blargg wrote:
> August Karlstrom wrote:
>> (E-Mail Removed) wrote:
>>> Hi
>>>
>>> Hope you can help me with this one. Is the following "C" code:
>>>
>>> short somevar, MethodName();
>>>
>>> shorthand for:
>>>
>>> short somevar = MethodName();
>>>
>>>
>>> where the MethodName() returns a short?

>> No, it's a shorthand for
>>
>> short somevar;
>> short MethodName();

>
> That's still shorthand.
>
> extern short int somevar;
> extern short int MethodName( ... );
>
> is fully longhand (drop the extern for somevar if this at function scope).


Drop the extern for somevar under ALL conditions. I.e. the following
requires a diagnostic and on many (most) implementations it will be a
fatal diagnostic.

extern short somevar;
int main(void)
{
return somevar;
}

However, if you get rid of the extern it is correct and will work.
--
Flash Gordon
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      01-16-2009
Flash Gordon <(E-Mail Removed)> writes:

> blargg wrote:
>> August Karlstrom wrote:
>>> (E-Mail Removed) wrote:
>>>> Hi
>>>>
>>>> Hope you can help me with this one. Is the following "C" code:
>>>>
>>>> short somevar, MethodName();
>>>>
>>>> shorthand for:
>>>>
>>>> short somevar = MethodName();
>>>>
>>>>
>>>> where the MethodName() returns a short?
>>> No, it's a shorthand for
>>>
>>> short somevar;
>>> short MethodName();

>>
>> That's still shorthand.
>>
>> extern short int somevar;
>> extern short int MethodName( ... );
>>
>> is fully longhand (drop the extern for somevar if this at function scope).

>
> Drop the extern for somevar under ALL conditions. I.e. the following
> requires a diagnostic and on many (most) implementations it will be a
> fatal diagnostic.


Not under all conditions at all. If somevar is in another unit then
extern is fine.

>
> extern short somevar;
> int main(void)
> {
> return somevar;
> }
>
> However, if you get rid of the extern it is correct and will work.


--
I'm not a person who particularly had heros when growing up.
- What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c.
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      01-16-2009
On 2009-01-16, (E-Mail Removed) <(E-Mail Removed)> wrote:
> Hi
>
> Hope you can help me with this one. Is the following "C" code:
>
> short somevar, MethodName();
>
> shorthand for:
>
> short somevar = MethodName();


You really should be using a language reference manual for this kind ``what is
the meaning of this basic syntax'' question.

That a declaration can have multiple comma-separate declarators which
share the same ``stem'' of specifiers and qualifiers, is knowledge
so basic that one has to conclude that you hardly know C at all.

If you hardly know C, learning it through a series of reference-manual-like
queries to a Usenet newsgroup isn't the most efficient way to get started.

I would suggest goint through a tutorial book, like _The C Programming
Language_ (second edition) by Kernighan and Ritchie.

> Would appreciate any comments/suggestions/explanations that you may
> have.


Just the above.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C conditional statement shorthand puzzle -- please help!! almurph@altavista.com C Programming 5 01-29-2009 01:56 PM
Shorthand for Property declaration in VB David W ASP .Net 0 01-17-2007 07:44 PM
Shorthand for namespaces Foxpointe XML 4 10-31-2006 09:41 PM
foreach shorthand unspammable@gmail.com C++ 2 03-25-2005 10:38 PM
kiwi biz q_'n <== Teeline shorthand for question Quean Computer Support 2 12-23-2004 07:08 AM



Advertisments