ptrs validity

A

Ancient_Hacker

Richard said:
Ancient_Hacker said:


If it points to an existing object or function, it's valid. Otherwise, it
isn't.

This might be helpful, I yell this at my son about once a year. It
helps: You're not the center of the universe. Other people have
different definitions, some of them just as valid in their context.
When you're responding to a human being, it's helpful to try to
interpret their words as they mean them, not as you do.
All the world's Linux/Windows, hmmm? Well, actually the world is a lot
bigger than that.

Ding Ding ding, we have a winner for the most disengenous comment this
year.

What market share do you suspect Linux+Unix+Windows have?
Probably 80% plus.

What market share do linkers have that do NOT print out a map file that
indicates the size of each segment?

I've never seen one that didnt. Let's be generous and say 1% of
linkers can't be asked to print out a map file with this basic info.

So I'm getting beat up for only covering 80 to 99% of the cases. Shame
on me.
 
A

Andrew Poelstra

The two most common C compilers, gcc and vc

Nice hair-splitting. When you type "gcc", what compiler do you get?

That's determined by the file extension. If you pass .c, you'll get a
C compiler; if you pass .cpp, you'll get a C++ compiler. I believe that
if you pass some .o files and nothing else, you'll get a linker.

Of course, that can be overridden by command-line parameters.
It has since version 3.3, June 2003. We're now in July, 2006, at
version 4.1. Your info is about three years out of date.

I can't imagine what use Keith would have for modern information on
GNU C; on this group he seems more concerned with ISO C.
I'm guessing the same applies to vc.

Nice try, but some of us have VC and don't have to guess and get the
facts right.

You poor soul.
 
D

David Resnick

Ancient_Hacker said:
The two most common C compilers, gcc and vc

Nice hair-splitting. When you type "gcc", what compiler do you get?




It has since version 3.3, June 2003. We're now in July, 2006, at
version 4.1. Your info is about three years out of date.

Lots of people are using older than that. We use 3.2.3 at work. In a
big organization, upgrading compiler versions without really good
reason is expensive.

I don't see it in 4.1.1 docs here:
http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/C-Extensions.html#C-Extensions

Do you have a reference for it? Not saying it isn't so, but I don't
see it.

-David
 
K

Keith Thompson

Ancient_Hacker said:
The two most common C compilers, gcc and vc

Nice hair-splitting. When you type "gcc", what compiler do you get?

It depends on the extension on the filename. "gcc tmp.c" compiles C.
"gcc tmp.C" or "gcc "tmp.cc" compiles C++. "gcc -c tmp.adb" compiles
Ada (if that option is installed).
It has since version 3.3, June 2003. We're now in July, 2006, at
version 4.1. Your info is about three years out of date.

I don't think so:
================================
% gcc --version
gcc (GCC) 4.0.2
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% cat tmp.c
int try;
int catch;
% gcc -c tmp.c
% cat tmp.C
int try;
int catch;
% gcc -c tmp.C
tmp.C:1: error: expected unqualified-id before 'try'
tmp.C:2: error: expected unqualified-id before 'catch'
================================

When I compile as C, "try" and "catch" are not treated as keywords.
When I compile as C++, they are. Furthermore, the "C Extensions"
section of the gcc documentation doesn't mention "try", "catch", or
exception handling.

You claim that gcc supports try and catch as an extension when
compiling C. Can you provide a sample program that uses this
extension, and a command line that will compile it?
I'm guessing the same applies to vc.

Nice try, but some of us have VC and don't have to guess and get the
facts right.

I have gcc, and I didn't have to guess to get the fact right. I'm
going to stick with my guess about vc for now.

In any case, the real point as far as this newsgroup is concerned is
that try and catch are not part of the standard C language. Any C
compiler *could* provide them as an extension, as long as it uses a
syntax that doesn't break any strictly conforming C program and/or
provides a conforming mode in which the extension is disabled. gcc
*could* provide try and catch as an extension (it has plenty of other
extensions), but even if it did, any code that used that extension
would not be portable.

(I think lcc-win32, which is not a C++ compiler, does support try and
catch or something similar, so it's certainly possible.)
 
K

Kenneth Brody

Ancient_Hacker said:
Keith Thompson wrote: [...]
The gcc C compiler does not, as far as I know, implement
try and catch as an extension to the C language.

It has since version 3.3, June 2003. We're now in July, 2006, at
version 4.1. Your info is about three years out of date.

I'm guessing the same applies to vc.

Nice try, but some of us have VC and don't have to guess and get the
facts right.

Strange, neither my gcc nor VC recognize "try".

gcc tells me:
foo.c: In function `main':
foo.c:6: `try' undeclared (first use in this function)

VC tells me:
foo.c
foo.c(6) : error C2065: 'try' : undeclared identifier

Yet, if I tell the compilers to use C++ mode, they take it.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
K

Keith Thompson

Ancient_Hacker said:
This might be helpful, I yell this at my son about once a year. It
helps: You're not the center of the universe. Other people have
different definitions, some of them just as valid in their context.
When you're responding to a human being, it's helpful to try to
interpret their words as they mean them, not as you do.

You're not yelling at your son. You're having a discussion in a
public newsgroup. Many of the other participants happen to be experts
in the C programming language.

Richard's proposed definition of "valid" seems perfectly reasonable.
If the OP wants to jump in and explain what he really meant, he's free
to do so.
Ding Ding ding, we have a winner for the most disengenous comment this
year.

What market share do you suspect Linux+Unix+Windows have?
Probably 80% plus.

What market share do linkers have that do NOT print out a map file that
indicates the size of each segment?

I've never seen one that didnt. Let's be generous and say 1% of
linkers can't be asked to print out a map file with this basic info.

So I'm getting beat up for only covering 80 to 99% of the cases. Shame
on me.

Yes.

We discuss the C programming language here, not "market share".
 
A

Al Balmer

This might be helpful, I yell this at my son about once a year. It
helps: You're not the center of the universe. Other people have
different definitions, some of them just as valid in their context.
When you're responding to a human being, it's helpful to try to
interpret their words as they mean them, not as you do.


Ding Ding ding, we have a winner for the most disengenous comment this
year.

What market share do you suspect Linux+Unix+Windows have?
Probably 80% plus.

<OT> Not by a long way. For a counterexample in one of the smaller
markets, last year there were four times as many cellphones sold as
PCs.
 
D

Default User

Keith said:
It depends on the extension on the filename. "gcc tmp.c" compiles C.
"gcc tmp.C" or "gcc "tmp.cc" compiles C++. "gcc -c tmp.adb" compiles
Ada (if that option is installed).

I seem to recall that it doesn't build properly unless you use g++,
because it doesn't link against the correct libraries. Compilation
isn't a problem though.




Brian
 
K

Keith Thompson

Default User said:
I seem to recall that it doesn't build properly unless you use g++,
because it doesn't link against the correct libraries. Compilation
isn't a problem though.

<OT>
I believe you're right. I probably should have used "gcc -c" for all
three examples. (The g++ command is similar to the gcc command,
except that it adds all the necessary arguments to link C++
correctly.)
</OT>
 
D

Default User

Keith said:
<OT>
I believe you're right. I probably should have used "gcc -c" for all
three examples. (The g++ command is similar to the gcc command,
except that it adds all the necessary arguments to link C++
correctly.)
</OT>

<OTOT>
That jibes with my recollection. It's one of those standard questions
that comes up on comp.lang.c++.
</OTOT>



Brian
 
M

Mark McIntyre

Well, disingenous at best. The two most common C compilers, gcc and vc
which together cover maybe 80% of the market, DO have try and catch.

No, they don't.

g++ and VC++ do, but they're not C compilers.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

The two most common C compilers, gcc and vc

Nice hair-splitting. When you type "gcc", what compiler do you get?

either gcc or g++, depending on the code suffix. Whats your point,
genius?
It has since version 3.3, June 2003. We're now in July, 2006, at
version 4.1. Your info is about three years out of date.

[mark@thelinux src]# gcc try.c
try.c: In function 'main':
try.c:4: error: 'try' undeclared (first use in this function)

[mark@thelinux src]# gcc -v
gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
I'm guessing the same applies to vc.

Nice try, but some of us have VC and don't have to guess and get the
facts right.

I have VC, and I can get the facts right too.

Compiling...
clc_test.c
clc_test.c(4) : error C2065: 'try' : undeclared identifier
clc_test.c(7) : warning C4013: 'catch' undefined; assuming extern
returning int
Error executing cl.exe.

clc_test.obj - 2 error(s), 1 warning(s)

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
R

Richard Bos

Ancient_Hacker said:
We don't know exactly what the OP meant by "valid", but let me guess
Usually when people ask about accessing A+3, they intend to use 32-bit
instructions to manipulate 8-bit data, sometimes with pre-fetch at the
end . A very common case is CRC-ing a network packet, which can be
done very speedily if you allow a little slop. Same with some
pattern-matching operations.

Which means the last time thru the loop the code might pre-fetch up to
3 bytes past the end of data. So all they might want to know is if the
memory is readable without major kabooms.

There isnt a way I know of in the C language to do this,

Of course there is a way in ISO C to do this. Just don't muck about with
possibly-invalid pointers and #ifdef LINUX-kernel-4.2 and Microsoftian
blunders like that, but simply make sure that you always allocate enough
memory for what you want to do in the first place. In the above case,
make sure the value you pass to malloc() is the smallest multiple of
four greater than or equal to the size of your data. How to determine
that value is left as an easy exercise for the reader.
Well, disingenous at best. The two most common C compilers, gcc and vc
which together cover maybe 80% of the market, DO have try and catch.

But not compatibly, TTBOMK, and not in C mode but in C++ mode, which
forces you to debilitate your code in other ways.
Well, for gnu and vc IIRC

And how were you going to do that in a _portable_ manner?
Yep, it's a non-portable technique. Moving the code to a new system
might take, oh, two hours to rename a few API calls.

_If_ those API calls are available on the new platform.
Versus stewing (as I have) for months trying to find unset pointers.

That just proves that the right way to go about this is to write code
that doesn't care in the first place. Do your bookkeeping properly; then
you won't _have_ to find unset pointers.
Programming involves a lot of analog value judgements. Is it better to
catch 3/4 of the problems, or just claim it's impossible?

It's better to write code that doesn't have the problem.
Is it okay to save a plane crashing by using a feature that has been
in 92% of the C compilers out there for a handful of years, even though
it's not in any standard, or do we just buy a flower-farm to send to
funerals?

It's better not to write code that needs the feature, especially when
lives depend on it.
Things arent always black and white. Many times a little openness to
shades of gray can be very helpful.

Thinking before you code, rather than halfway through when you notice
that you've made some unwarranted assumptions, is more helpful.

Richard
 
M

Michael Wojcik

Actually, MS VC++ implements _try as an extension to C.

More specifically (and OT, of course, but for the sake of clarity),
if extensions are enabled, MS VC recognizes the additional keywords
__try, __except, __finally, __leave, and GetExceptionCode (which
looks like a function but is actually a keyword).[1]

These keywords can be used to instruct the compiler to generate code
for Windows Structured Exception Handling, which is not a language
feature, but an OS one. It is completely separate from the C++
exception mechanism, for example, and conflating the two as
"Ancient_Hacker" did is deceptive.


1. Depending on headers included, etc, variations of these may be
defined as object-style macros, so "_try" and "try" may be defined
as aliases for "__try". As of VC6, however, the double-underscore
forms are the official ones.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top