Print slashes using C


 
Thread Tools Search this Thread
Top Forums Programming Print slashes using C
# 8  
Old 05-14-2013
(Apologies for any typos.)

There is the possibility of the compiler itself compiling oddly...

I wrote a simple C proggy to R/W from/to memory for the AMIGA and it compiled and ran perfectly using Dice-C but failed to even compile on VBCC... So I set about doing the subtleties of each compiler until both gave the correct working results...

I then attempted to compile the same finalised source code on Windows VC6 and gcc on Knoppix 3.?. They compiled perfectly but did not run for obvious reasons...

So maybe the compiler is a little _pedantic_ and requires _its_ correct grammar...

;o)
# 9  
Old 05-14-2013
There's usually a subset that will work fine in any of them. The trick is NOT using Microsoft's preferred structures but finding others they haven't managed to break yet...

It's difficult to imagine the OP's program was actually broken.

Last edited by Corona688; 05-14-2013 at 02:30 PM..
# 10  
Old 05-14-2013
Quote:
Originally Posted by wisecracker
There is the possibility of the compiler itself compiling oddly...

...So I set about doing the subtleties of each compiler until both gave the correct working results...

So maybe the compiler is a little _pedantic_ and requires _its_ correct grammar...
There's noting wrong with the code in post #1. Since whitespace is not relevant to C, there is no functional difference between the original code and what you posted in post #2.

While compilers often make extensions available, and while some aspects of standard C are implementation-defined, there is nothing in the OP's code that falls into either category.

The simplest and most likely explanation is that the OP did not post the code that generated the message. Perhaps a slight difference went unnoticed and was lost during debugging.

Moving int i; up a line, to create a pre-ANSI function definition, causes gcc 4.1.2 to produce an identical message.

Regards,
Alister
# 11  
Old 05-14-2013
Hi alister...

Quote:
There's noting wrong with the code in post #1.
I never wrote that there was! I only used one word in my original reply "Try:-".

Quote:
Since whitespace is not relevant to C, there is no functional difference between the original code and what you posted in post #2.
Again I never quoted that it was relevant. The difference is I never make assumptions without quoting them. Hence my last reply; defferent compilers for the same language DO give differing end result executables on the same platform.

Although I rarely touch C(++) these days I never trust any C compiler and always compile using different platforms. It does not matter that some source code might NOT run on some platforms - for example R/W from/to memory as some machines do not have MMUs... Machines with MMUs WILL give Segmentation fault(s) but that does not mean the code is faulty just that the platform with an MMU creates the event.

My modified code just made it much more easy to read and seemed to help the guy in question and that is all that really matters - is it not?

I am now clear...
# 12  
Old 05-14-2013
Quote:
Originally Posted by wisecracker
Although I rarely touch C(++) these days I never trust any C compiler and always compile using different platforms. It does not matter that some source code might NOT run on some platforms - for example R/W from/to memory as some machines do not have MMUs... Machines with MMUs WILL give Segmentation fault(s) but that does not mean the code is faulty just that the platform with an MMU creates the event.
I've programmed C in DOS, Windows, Linux, Solaris, WinCE/ARM, and a few embedded platforms, building and/or using libraries that port between most or all of those. There are ways to write portable C code.

Writing to static strings will segfault on some platforms as you mentioned. The answer is to not do that; it's always been a dirty trick, technically speaking, but some compilers just happen to let you get away with it.

Quote:
My modified code just made it much more easy to read and seemed to help the guy in question and that is all that really matters - is it not?
Not when the original question remains unresolved. I am completely certain now, that the code he posted is not the code that caused the error. So the 'solutions' are misleading at best.
# 13  
Old 05-14-2013
Quote:
Originally Posted by wisecracker
I never wrote that there was! I only used one word in my original reply "Try:-".
...
Again I never quoted that it was relevant.
You misunderstood me. I wasn't suggesting that you had made either assertion. I mentioned the code's correctness and whitespace's syntactical irrelevance only to point out that while your code suggestion appears to have fixed the problem for the OP, it could not have done so unless there is a very, very fundamental bug with a very popular and tested compiler -- a bug in which the presence of whitespace where it should not have any effect is the difference between code that compiles and code which does not; this is not impossible, but it is highly unlikely (particularly when transposing two adjacent lines of code produces an identical error message).

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 14  
Old 05-14-2013
Hi Corona688...

Quote:
Not when the original question remains unresolved. I am completely certain now, that the code he posted is not the code that caused the error. So the 'solutions' are misleading at best.
The problem is unless we know that for a fact then the ONLY assumption we can come to is the compilation itself.

As alister has pointed out, the given compiler has had _eons_ of proof tesing but that does not make it entirely bullet proof. Assuming the OP's code IS as he originally wrote it and he compiled it the way he did, giving the result on screen as shown, then perhaps - just a miniscule perhaps - there might be a very rare bug in the compiler...

I would not want to put my life on it, but the only real test is for the OP to go back to his original code and see if he can recreate the same error...

Anyhow as a mere amateur I do trust you professinals and your replies and will bow out gracefully... ;o)

Bye...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to extract the data between slashes

I have got the following contents and please can you advise me on how to extract the following data that appears between the very first slashes. Thanks i.e 576 , 10000, 1299 3/576/GPP///////NONE/0 50/10000/GPP///D4////GPP/0 234/1299/GPP///////NONE/0 (3 Replies)
Discussion started by: Sudhakar333
3 Replies

2. Cybersecurity

Server is ignoring slashes

When I try to access my website's Administrator page (mysite.com/administrator), I'm redirected to (mysite.comadministrator), as if the slash was removed from the URL The funny thing is that I can access it if I enter 2 slashes (mysite.com//administrator) Any ideas of what might be causing it? (4 Replies)
Discussion started by: rlopes
4 Replies

3. Shell Programming and Scripting

How to use sed when a match has forward slashes

I'm trying to replace an alias with its match using sed but the match contains forward slashs so it causes the sed command to throw a garbled message.. cmd_list.txt sample AIX_myserver_1011_vintella.sudoers_cmndalias sample I'm trying to use the below but like I say it throws a... (5 Replies)
Discussion started by: Jazmania
5 Replies

4. Shell Programming and Scripting

question on blackslashes and slashes in directories

Since I'm usually on windows I've came across different shells like Cygwin, Hamilton, and MKS. I've been working in csh most of the time, so porting scripts from one shell to another can be fairly annoying and confusing. When specifying a directory I noticed that certain shells do not recognize... (1 Reply)
Discussion started by: vas28r13
1 Replies

5. Shell Programming and Scripting

search replace pattern containing slashes

Need help in finding pattern then replacing pattern that contains multiple slashes .. ex . <imgp src="Attention_web.eps.jpg" align="left"> <imgp src="NewToday062308.eps.jpg"> replace with <imgp src="/ww2/adpay/liner/Attention_web.eps.jpg" align="left"> <imgp... (2 Replies)
Discussion started by: aveitas
2 Replies

6. UNIX for Dummies Questions & Answers

dots and slashes

when I execute a command in like "run.sh," I can run it two ways: ./run.sh or . run.sh What is the difference? (1 Reply)
Discussion started by: DarkLord
1 Replies

7. UNIX for Dummies Questions & Answers

sed command for using with back slashes

hi all, im trying to use a sed command to remove all occurenes of \p\g what i used so far is : sed 's!\p\g!!g' file but this doesnt work ? Any ideas, thanks for helping. (2 Replies)
Discussion started by: seaten
2 Replies

8. UNIX for Dummies Questions & Answers

Password slashes.

Hi everyone! :) I've been asked to write an article breaking down the basics of UNIX password information etc., and I've come across something in which I cannot find a definition for within Google. Very simply, can anyone tell me what the difference is between a standard UNIX password, and... (4 Replies)
Discussion started by: hellz
4 Replies

9. Shell Programming and Scripting

slashes in a bash shell

Substituting the / for the \ I came up with this: sed s/\\\\usr\\\\qm/\\\\\\\\qmi/g Can anyone explain to me please, why I have to pass the slash four times? :confused: (2 Replies)
Discussion started by: Shakey21
2 Replies

10. UNIX for Dummies Questions & Answers

UNIX and forward slashes

Hey, This is probably going to sound like an immensely stupid and dull question, but can someone please tell me whether the forward slash on the web address (http://) signifies that it is running on UNIX? hanks (1 Reply)
Discussion started by: steverocliffe
1 Replies
Login or Register to Ask a Question